Using SpringBoot 2.4.0, Jackson 2.11.3 along with Java 11, I get a deserialization error when using an enum with a @JsonCreator factory in a simple input model.
Here is a minimal project for reproduction:
https://github.com/lpellegr/springboot-enum-jsoncreator
- Run
./gradlew bootRun.
- Open
http://localhost:8888/demo/1?every=d in your browser
My purpose is to use a custom enum value representation for serialization/deserializaton.
The enum in question in the example is named EveryEnum. When I serialize EveryEnum.DAYS, I expect d in output. When I deserialize (i.e. receive d as input in a controller), I expect EveryEnum.DAYS.
The @jsonvalue annotation works properly and is used when serializing the enum value. However, the @JsonCreator seems completely ignored.
The error I get is the following:
Caused by: org.springframework.core.convert.ConversionFailedException: Failed to convert from type [java.lang.String] to type [com.example.demo.EveryEnum] for value 'd'; nested exception is java.lang.IllegalArgumentException: No enum constant com.example.demo.EveryEnum.d
The problem seems not specific to version 2.4.0 of Spring Boot. At least, I get the same problem with version 2.3.6. Also, testing deserialization directly using an ObjectMapper instance works properly.
All this combined along with the error message lets me think this is simply a use case that is not supported by Spring Boot. Is there a specific reason? it is a bug or a feature request?
Using SpringBoot 2.4.0, Jackson 2.11.3 along with Java 11, I get a deserialization error when using an enum with a @JsonCreator factory in a simple input model.
Here is a minimal project for reproduction:
https://github.com/lpellegr/springboot-enum-jsoncreator
./gradlew bootRun.http://localhost:8888/demo/1?every=din your browserMy purpose is to use a custom enum value representation for serialization/deserializaton.
The enum in question in the example is named EveryEnum. When I serialize EveryEnum.DAYS, I expect d in output. When I deserialize (i.e. receive d as input in a controller), I expect EveryEnum.DAYS.
The @jsonvalue annotation works properly and is used when serializing the enum value. However, the @JsonCreator seems completely ignored.
The error I get is the following:
The problem seems not specific to version 2.4.0 of Spring Boot. At least, I get the same problem with version 2.3.6. Also, testing deserialization directly using an ObjectMapper instance works properly.
All this combined along with the error message lets me think this is simply a use case that is not supported by Spring Boot. Is there a specific reason? it is a bug or a feature request?