Using: * spring boot 2.7.18 * JDK 17.0.10
When I map a RequestBody to a Java-enum, then KotlinSerializationJsonHttpMessageConverter takes precedence over the Jackson HttpMessageConverter. Although this is not what i'd prefer, it works in most cases, unless that enum contains an @JsonValue to specify a different mapping. Then I get following exception:
HttpMessageNotReadableException: Could not read JSON: Unexpected JSON token at offset 0: Expected quotation mark '"', but had 't' instead at path: $ JSON input: test; nested exception is kotlinx.serialization.json.internal.JsonDecodingException: Unexpected JSON token at offset 0: Expected quotation mark '"', but had 't' instead at path: $
@RestController
public class TestController {
@PostMapping(value = "/api/test")
public Object post(@RequestBody TestEnum testEnum) {
return testEnum;
}
}
public enum TestEnum {
TEST("test");
@JsonValue
@Getter
private String value;
TestEnum(String value) {
this.value = value;
}
}
Comment From: wilkinsona
Spring Boot 2.7.x is no longer supported. Please upgrade to Spring Boot 3.2.x or later as soon as possible.
The exact behaviour of KotlinSerializationJsonHttpMessageConverter is out of Spring Boot's control as it's part of Spring Framework and builds upon the kotlinx.serialization library.
That KotlinSerializationJsonHttpMessageConverter is being used rather than a Jackson-based converter is a duplicate of https://github.com/spring-projects/spring-boot/issues/39853 and https://github.com/spring-projects/spring-boot/issues/24238. As described in #39853, you can use a custom HttpMessageConverters bean to control the ordering.