-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Deserialization of enums with enum values annotated with the same @JsonProperty value leads to InvalidDefinitionException: Multiple fields representing property #4606
Comments
Why do you have |
The example above is not production code. We depend on a separate library internal to our company. There, they use this to serialize two enum values to the same string, I guess (I will report why they use this once I get an answer from them). Im not sure if the old behaviour is by design or just a coincidence. Nevertheless it is a breaking change to 2.15.4 |
The new code seems more correct. We cannot deserialize properly if 2 enum values have the same text representation. My vote would be to keep the new code as is. |
I agree: there is a genuine conflict. While I can see why for serialization-only use case someone might want to have 2 enum choices serialize into same String, this is currently not supported; and I am not sure it could be like this, given that |
A team member responsible for this internal library will comment here why they used this functionality exactly. From my point of view as the creator of this issue I am also happy with the current behaviour in 2.16.2 upwards. |
@noahzuch That would be interesting to hear about. And even if the new behavior were to remain, it is good there is a report for this change in case someone else is affected. |
Search before asking
Describe the bug
I'm using a thirdparty client that is deserializing json where in an enum multiple values are annotated with the same
@JsonProperty
value. When upgrading our dependencies from Jackson 2.15.4 to 2.17.1 (via Spring Boot 3.3.1) this API started failing with:com.fasterxml.jackson.databind.exc.InvalidDefinitionException: Multiple fields representing property ...
This issue seems similar to #4409, but is still present in 2.16.2.
Version Information
2.16.2 to 2.17.1
Reproduction
I modified the example in #4409 to use
@JsonProperty
Expected behavior
Whether or not the old behaviour is expected, i can not tell. All I know is that in 2.15.4 it seems like the last enum property with the given
@JsonProperty
is used. So when execution the code above, the valueRGBA
is printed in the console. When switching the order ofRGBA
undRGBa
, thenRGBa
is printed.The current behaviour in 2.16.2 up to 2.17.1 is an exception when deserializing saying:
com.fasterxml.jackson.databind.exc.InvalidDefinitionException: Multiple fields representing property "RGBA": my.package.Temp$Bug$ColorMode#RGBA vs my.package.Temp$Bug$ColorMode#RGBa at [Source: REDACTED (
StreamReadFeature.INCLUDE_SOURCE_IN_LOCATIONdisabled); line: 1, column: 1]
Additional context
No response
The text was updated successfully, but these errors were encountered: