-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
New values make Enums backward incompatible #728
Comments
@avadhoot When you introduce a new value into an enum that was not present previously, you have made a breaking change to the API, since the new data will no longer be valid against the previous schema. Clients will not expect to receive this value so this is a breaking change. I can see that So if I understand this correctly, We could always implement our own config flag here to allow unknown enum values, so we would replace this code: MyEnum constant = (MyEnum)constants.get(value);
if(constant == null) {
throw new IllegalArgumentException(value);
} else {
return constant;
} with this code: return (MyEnum)constants.get(value); However I think this is really a Jackson issue. |
I've raised a PR against jackson-databind: |
Thanks a lot for taking the time to fix this issue. |
Problem: If I add a new value to an existing Enum and start returning it from my service any client who has not upgraded to the latest version of the JAR containing the new Enum will start getting exceptions during deserialization even if the DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_AS_NULL has been set to enabled.
Here is a sample Enum being returned from the service:
This is the Enum on the client side:
Now if the service returns 'VALUE3' then the client's deserialization will fail even if DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_AS_NULL is enabled.
The reason for this is that the ObjectMapper's deserialization method will always call fromValue as it is annotated with @JsonCreator. If this annotation is removed the toString method gets called which won't throw the exception but return NULL which can then be handled by the client.
My requirement is for the Enums to be backward compatible to support clients which integrate with older versions of my service response.
What is the best way to handle this problem?
The text was updated successfully, but these errors were encountered: