question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Enum Names Not Overriden with @JsonProperty

See original GitHub issue
Q 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:closed
  • Created 6 years ago
  • Comments:8 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
jlouscommented, May 24, 2020

@rabiori Ever find a workaround?

1reaction
rabioricommented, Jun 27, 2019

any workarounds for someone stuck in the old version

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found