diff --git a/release-notes/VERSION-2.x b/release-notes/VERSION-2.x index 2a26d24822..ca85c275ec 100644 --- a/release-notes/VERSION-2.x +++ b/release-notes/VERSION-2.x @@ -6,6 +6,9 @@ Project: jackson-databind 2.18.0 (not yet released) +#4119: Exception when deserialization uses a record with a constructor + property with `access=READ_ONLY` + (reported by @Mochis) #4452: `@JsonProperty` not serializing field names properly on `@JsonCreator` in Record (reported by @Incara) diff --git a/src/test/java/com/fasterxml/jackson/failing/CreatorWithReadOnlyParam4119Test.java b/src/test/java/com/fasterxml/jackson/databind/deser/creators/CreatorWithReadOnlyParam4119Test.java similarity index 95% rename from src/test/java/com/fasterxml/jackson/failing/CreatorWithReadOnlyParam4119Test.java rename to src/test/java/com/fasterxml/jackson/databind/deser/creators/CreatorWithReadOnlyParam4119Test.java index 0d284d2c02..7803b0fc4d 100644 --- a/src/test/java/com/fasterxml/jackson/failing/CreatorWithReadOnlyParam4119Test.java +++ b/src/test/java/com/fasterxml/jackson/databind/deser/creators/CreatorWithReadOnlyParam4119Test.java @@ -1,4 +1,4 @@ -package com.fasterxml.jackson.failing; +package com.fasterxml.jackson.databind.deser.creators; import org.junit.jupiter.api.Test; diff --git a/src/test/java/com/fasterxml/jackson/databind/deser/creators/DelegatingCreatorImplicitNames2543Test.java b/src/test/java/com/fasterxml/jackson/databind/deser/creators/DelegatingCreatorImplicitNames2543Test.java index 9cde9c061c..6288328084 100644 --- a/src/test/java/com/fasterxml/jackson/databind/deser/creators/DelegatingCreatorImplicitNames2543Test.java +++ b/src/test/java/com/fasterxml/jackson/databind/deser/creators/DelegatingCreatorImplicitNames2543Test.java @@ -20,7 +20,7 @@ public class DelegatingCreatorImplicitNames2543Test extends DatabindTestUtil { - static class Data { + static class Data2543 { final String part1; final String part2; @@ -28,7 +28,7 @@ static class Data { // this creator is considered a source of settable bean properties, // used during deserialization @JsonCreator(mode = PROPERTIES) - public Data(@JsonProperty("part1") String part1, + public Data2543(@JsonProperty("part1") String part1, @JsonProperty("part2") String part2) { this.part1 = part1; this.part2 = part2; @@ -37,14 +37,15 @@ public Data(@JsonProperty("part1") String part1, // no properties should be collected from this creator, // even though it has an argument with an implicit name @JsonCreator(mode = DELEGATING) - public static Data fromFullData(String fullData) { + public static Data2543 fromFullData(String fullData) { String[] parts = fullData.split("\\s+", 2); - return new Data(parts[0], parts[1]); + return new Data2543(parts[0], parts[1]); } } static class DelegatingCreatorNamedArgumentIntrospector - extends JacksonAnnotationIntrospector { + extends JacksonAnnotationIntrospector + { private static final long serialVersionUID = 1L; @Override @@ -67,7 +68,7 @@ public String findImplicitPropertyName(AnnotatedMember member) { @Test public void testDeserialization() throws Exception { - Data data = MAPPER.readValue(a2q("{'part1':'a','part2':'b'}"), Data.class); + Data2543 data = MAPPER.readValue(a2q("{'part1':'a','part2':'b'}"), Data2543.class); assertThat(data.part1).isEqualTo("a"); assertThat(data.part2).isEqualTo("b"); @@ -75,7 +76,7 @@ public void testDeserialization() throws Exception { @Test public void testDelegatingDeserialization() throws Exception { - Data data = MAPPER.readValue(a2q("'a b'"), Data.class); + Data2543 data = MAPPER.readValue(a2q("'a b'"), Data2543.class); assertThat(data.part1).isEqualTo("a"); assertThat(data.part2).isEqualTo("b"); diff --git a/src/test/java/com/fasterxml/jackson/databind/deser/creators/DelegatingExternalProperty1003Test.java b/src/test/java/com/fasterxml/jackson/databind/deser/creators/DelegatingExternalProperty1003Test.java index c2d69af74f..c014567453 100644 --- a/src/test/java/com/fasterxml/jackson/databind/deser/creators/DelegatingExternalProperty1003Test.java +++ b/src/test/java/com/fasterxml/jackson/databind/deser/creators/DelegatingExternalProperty1003Test.java @@ -5,40 +5,42 @@ import com.fasterxml.jackson.annotation.*; import com.fasterxml.jackson.databind.*; +import com.fasterxml.jackson.databind.testutil.DatabindTestUtil; import static org.junit.jupiter.api.Assertions.assertTrue; -public class DelegatingExternalProperty1003Test +public class DelegatingExternalProperty1003Test extends DatabindTestUtil { - static class HeroBattle { + // [databind#1003] + public interface Hero1003 { } - private final Hero hero; + static class HeroBattle1003 { - HeroBattle(Hero hero) { + private final Hero1003 hero; + + HeroBattle1003(Hero1003 hero) { if (hero == null) throw new Error(); this.hero = hero; } @JsonTypeInfo(use = JsonTypeInfo.Id.CLASS, include = JsonTypeInfo.As.EXTERNAL_PROPERTY, property = "heroType") - public Hero getHero() { + public Hero1003 getHero() { return hero; } @JsonCreator - static HeroBattle fromJson(Delegate json) { - return new HeroBattle(json.hero); + static HeroBattle1003 fromJson(Delegate1003 json) { + return new HeroBattle1003(json.hero); } } - static class Delegate { + static class Delegate1003 { @JsonProperty @JsonTypeInfo(use = JsonTypeInfo.Id.CLASS, include = JsonTypeInfo.As.EXTERNAL_PROPERTY, property = "heroType") - public Hero hero; + public Hero1003 hero; } - public interface Hero { } - - static class Superman implements Hero { + static class Superman1003 implements Hero1003 { String name = "superman"; public String getName() { @@ -46,15 +48,15 @@ public String getName() { } } + // [databind#1003] @Test public void testExtrnalPropertyDelegatingCreator() throws Exception { - ObjectMapper mapper = new ObjectMapper(); - - final String json = mapper.writeValueAsString(new HeroBattle(new Superman())); + ObjectMapper mapper = newJsonMapper(); - final HeroBattle battle = mapper.readValue(json, HeroBattle.class); + final String json = mapper.writeValueAsString(new HeroBattle1003(new Superman1003())); + final HeroBattle1003 battle = mapper.readValue(json, HeroBattle1003.class); - assertTrue(battle.getHero() instanceof Superman); + assertTrue(battle.getHero() instanceof Superman1003); } }