admin管理员组

文章数量:1122832

After update jackson kotlin module from 2.17 to 2.18 I have strange errors.

DTO is

data class StopWordModifyRequest(
    @field:NotEmpty
    @field:Size(min = 2, max = 255)
    val word: String,
) : Serializable

test

        mvc
            .post(API_ROUTE) {
                addCommonHeaders(KNOWN_USER_ID, ADMIN_ROLE)
                content = """
                    {
                        "word": "childTest"
                    }
                """
            }.andExpect { status { isCreated() } }

it works in 2.17, but error in 2.18:

Body = {"message":"Request body is invalid","details":[{"name":null,"description":"Cannot construct instance of `x.y.z.StopWordModifyRequest` (although at least one Creator exists): cannot deserialize from Object value (no delegate- or property-based Creator)\n at [Source: REDACTED (`StreamReadFeature.INCLUDE_SOURCE_IN_LOCATION` disabled); line: 3, column: 25]"}]}

I can't google it quickly

After update jackson kotlin module from 2.17 to 2.18 I have strange errors.

DTO is

data class StopWordModifyRequest(
    @field:NotEmpty
    @field:Size(min = 2, max = 255)
    val word: String,
) : Serializable

test

        mvc
            .post(API_ROUTE) {
                addCommonHeaders(KNOWN_USER_ID, ADMIN_ROLE)
                content = """
                    {
                        "word": "childTest"
                    }
                """
            }.andExpect { status { isCreated() } }

it works in 2.17, but error in 2.18:

Body = {"message":"Request body is invalid","details":[{"name":null,"description":"Cannot construct instance of `x.y.z.StopWordModifyRequest` (although at least one Creator exists): cannot deserialize from Object value (no delegate- or property-based Creator)\n at [Source: REDACTED (`StreamReadFeature.INCLUDE_SOURCE_IN_LOCATION` disabled); line: 3, column: 25]"}]}

I can't google it quickly

Share Improve this question asked Nov 21, 2024 at 11:53 HettHett 3,7632 gold badges38 silver badges56 bronze badges 1
  • hmm github.com/FasterXML/jackson-module-kotlin/issues/846 – Hett Commented Nov 21, 2024 at 12:00
Add a comment  | 

1 Answer 1

Reset to default 0

Rather a little late but I encountered the exact same behavior today (migrating from Jackson 2.17 to 2.18).

Was able, with some effort, to figure out the issue and a clean solution.

Jackson, not being able to find the constructor, is very clearly the root cause. And I'm inclined to believe the problem occurs in the specific scenario of multiple existing constructors.

The clean and very straightforward solution is to add the @JsonCreator annotation for each constructor Jackson will be using. Somehow it was decided this annotation is required as of 2.18 while it was not required before.

本文标签: