Skip to content

Autoconfigured HttpMessageConverter for Kotlin throws Exception for Java Enum. #40987

@ironbirdie

Description

@ironbirdie

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;
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions