From 7abea59e1ce2af324fe0bbc2bfd6bda9d4a94589 Mon Sep 17 00:00:00 2001 From: "Kim, Joo Hyuk" Date: Tue, 1 Jul 2025 01:50:33 +0900 Subject: [PATCH] Add failing test for #5210 --- .../tofix/ConstructorDetector5210Test.java | 60 +++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 src/test/java/com/fasterxml/jackson/databind/tofix/ConstructorDetector5210Test.java diff --git a/src/test/java/com/fasterxml/jackson/databind/tofix/ConstructorDetector5210Test.java b/src/test/java/com/fasterxml/jackson/databind/tofix/ConstructorDetector5210Test.java new file mode 100644 index 0000000000..64e0ebf72c --- /dev/null +++ b/src/test/java/com/fasterxml/jackson/databind/tofix/ConstructorDetector5210Test.java @@ -0,0 +1,60 @@ +package com.fasterxml.jackson.databind.tofix; + +import org.junit.jupiter.api.Test; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.cfg.ConstructorDetector; +import com.fasterxml.jackson.databind.json.JsonMapper; +import com.fasterxml.jackson.databind.testutil.failure.JacksonTestFailureExpected; + +import static org.junit.jupiter.api.Assertions.assertThrows; + +public class ConstructorDetector5210Test { + + // succeeds with 2.12.7 + // also succeeds with 2.17.0, 2.17.2, 2.18.0, 2.18.1, 2.18.2 + // fails with 2.18.3+ + @JacksonTestFailureExpected + @Test + public void testSerialization() throws JsonProcessingException { + String json = "{\"someFiled\":\"imSomeStringVal\"}"; + + ObjectMapper objectMapper = JsonMapper.builder() + .constructorDetector(ConstructorDetector.USE_PROPERTIES_BASED) + .build(); + + // no exception starting from 2.18.3 + assertThrows(JsonMappingException.class, () -> { + objectMapper.readValue(json, WrapperClass.class); + }); + } + + public static class WrapperClass { + @JsonProperty("someFiled") + private final SingleStringClass someFiled; + + private WrapperClass() { + someFiled = null; + } + + public WrapperClass(SingleStringClass someFiled) { + this.someFiled = someFiled; + } + } + + public static class SingleStringClass { + @JsonProperty("someStringVal") + private final String someStringVal; + + private SingleStringClass() { + someStringVal = null; + } + + public SingleStringClass(String someStringVal) { + this.someStringVal = someStringVal; + } + } +}