Skip to content
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

Breaking change between in handling enums with @JsonCreator #3061

Closed
skuhnert opened this issue Feb 19, 2021 · 2 comments
Closed

Breaking change between in handling enums with @JsonCreator #3061

skuhnert opened this issue Feb 19, 2021 · 2 comments
Labels
duplicate Duplicate of an existing (usually earlier) issue

Comments

@skuhnert
Copy link

I am facing an error after updating from Version 2.10.1 to 2.11.3:

com.fasterxml.jackson.databind.exc.ValueInstantiationException: Cannot construct instance of NumberEnum, problem: argument type mismatch
at [Source: (String)"{
"myNumber" : 2
}"; line: 2, column: 16] (through reference chain: Demo["myNumber"])
at com.fasterxml.jackson.databind.exc.ValueInstantiationException.from(ValueInstantiationException.java:47)
at com.fasterxml.jackson.databind.DeserializationContext.instantiationException(DeserializationContext.java:1758)
at com.fasterxml.jackson.databind.DeserializationContext.handleInstantiationProblem(DeserializationContext.java:1128)
at com.fasterxml.jackson.databind.deser.std.FactoryBasedEnumDeserializer.deserialize(FactoryBasedEnumDeserializer.java:159)
at com.fasterxml.jackson.databind.deser.impl.MethodProperty.deserializeAndSet(MethodProperty.java:129)
at com.fasterxml.jackson.databind.deser.BeanDeserializer.vanillaDeserialize(BeanDeserializer.java:293)
at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserialize(BeanDeserializer.java:156)
at com.fasterxml.jackson.databind.ObjectMapper._readMapAndClose(ObjectMapper.java:4526)
at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:3468)
at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:3436)
at EnumMapperTest.test(EnumMapperTest.java:16)

It seems there was a change in handling the datatype while deserializing an enum (in FactoryBasedEnumSererializer.java).

In my case, I annotated a factory method for an Integer-Enum like so:
https://github.com/comlinegmbh/jackson-enum-poc/blob/master/src/main/java/NumberEnum.java

Using Integer instead of String as an argument of "fromValue" fixes the Problem in both V2.10.1 and V2.11.3.

Unfortunately this code is generated from an openapi schema via swagger-codegen. I will create a similar issue there but want to share this finding here, so you can be beware of it.

I have also created a small example-project so you can comprehend this issue easily:
https://github.com/comlinegmbh/jackson-enum-poc

Switching the Version in the pom.xml makes the unit-test succeed.

Feel free to let me know if this is no bug but the new intended behavior.

@jool
Copy link

jool commented May 20, 2021

Please refer to the following issues which I believe are the same as yours:

I'm inclined to consider this an issue with swagger-codegen.

@cowtowncoder
Copy link
Member

Same as #3006, will be fixed in 2.13.1.

@cowtowncoder cowtowncoder added the duplicate Duplicate of an existing (usually earlier) issue label Oct 24, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
duplicate Duplicate of an existing (usually earlier) issue
Projects
None yet
Development

No branches or pull requests

3 participants