Enum Names Not Overriden with @JsonProperty
See original GitHub issueQ | A |
---|---|
Bug or feature request? | Bug |
Which Swagger-Core version? | 1.5.18 |
Which Java version? | 1.8u151 |
Which JAX-RS framework & version? | RESTEasy 3.0.19 with JAX-RS 2.0 |
Using @JsonProperty
to override enum names isn’t working. The following example below:
public enum SomeEnum {
@JsonProperty("num-one")
NUMONE,
@JsonProperty("num-two")
NUMTWO
}
results in an OpenAPI file that looks like:
"enum": [
"NUMONE",
"NUMTWO"
]
instead of the expected:
"enum": [
"num-one",
"num-two"
]
The issue is in ModelResolver which is using the deprecated Jackson Databind method findEnumValue
to read in the enum name. This method does not look for any overrides and just defaults to the name in the code. Using the replacement method findEnumValues
fixes this problem.
Issue Analytics
- State:
- Created 6 years ago
- Comments:8 (2 by maintainers)
Top Results From Across the Web
Customizing enum constant names with Jackson
Since Jackson 2.6, you can annotate your enum constants with @JsonProperty to give them a custom name. The javadoc states.
Read more >How To Serialize and Deserialize Enums with Jackson
In this quick tutorial, we'll learn how to control the way Java Enums are serialized and deserialized with Jackson 2.
Read more >JsonProperty.Access (Jackson-annotations 2.6.0 API)
Returns the enum constant of this type with the specified name. The string must match exactly an identifier used to declare an enum...
Read more >Jackson JSON - Using @JsonEnumDefaultValue to ... - LogicBig
JsonEnumDefaultValue annotation can be used on an enum element to define a default (fallback) value used during deserialize.
Read more >How to write custom converters for JSON serialization - .NET
To override the default behavior of a built-in converter. ... Json with functionality not included in the current release.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@rabiori Ever find a workaround?
any workarounds for someone stuck in the old version