From 6b20100b58257349404ecd840c5b511f285fd359 Mon Sep 17 00:00:00 2001 From: Tatu Saloranta Date: Sun, 21 Feb 2021 14:37:58 -0800 Subject: [PATCH] Mark #754 as fixed (actual fix bit earlier, same as #3045 presumably) --- release-notes/CREDITS-2.x | 5 + release-notes/VERSION-2.x | 3 + .../ext/ExternalTypeIdWithCreatorTest.java | 98 +++++++++---------- 3 files changed, 57 insertions(+), 49 deletions(-) diff --git a/release-notes/CREDITS-2.x b/release-notes/CREDITS-2.x index 11fd38215e..e8a8373301 100644 --- a/release-notes/CREDITS-2.x +++ b/release-notes/CREDITS-2.x @@ -1300,6 +1300,11 @@ SunYiJun (xiaosunzhu@github) having namingStrategy (2.12.1) +Vassil Dichev (vdichev@github) + * Reported #754: EXTERNAL_PROPERTY does not work well with `@JsonCreator` and + `FAIL_ON_UNKNOWN_PROPERTIES` + (2.12.2) + Miguel G (Migwel@github) * Reported, contributed fix for #3025: UntypedObjectDeserializer` mixes multiple unwrapped collections (related to #2733) diff --git a/release-notes/VERSION-2.x b/release-notes/VERSION-2.x index c51ba49b00..7474fedc2b 100644 --- a/release-notes/VERSION-2.x +++ b/release-notes/VERSION-2.x @@ -6,6 +6,9 @@ Project: jackson-databind 2.12.2 (not yet released) +#754: EXTERNAL_PROPERTY does not work well with `@JsonCreator` and + `FAIL_ON_UNKNOWN_PROPERTIES` + (reported by Vassil D) #3008: String property deserializes null as "null" for `JsonTypeInfo.As.EXTERNAL_PROPERTY` #3022: Property ignorals cause `BeanDeserializer `to forget how to read diff --git a/src/test/java/com/fasterxml/jackson/databind/jsontype/ext/ExternalTypeIdWithCreatorTest.java b/src/test/java/com/fasterxml/jackson/databind/jsontype/ext/ExternalTypeIdWithCreatorTest.java index 4e29a9e86a..89e6cc13cd 100644 --- a/src/test/java/com/fasterxml/jackson/databind/jsontype/ext/ExternalTypeIdWithCreatorTest.java +++ b/src/test/java/com/fasterxml/jackson/databind/jsontype/ext/ExternalTypeIdWithCreatorTest.java @@ -6,6 +6,37 @@ public class ExternalTypeIdWithCreatorTest extends BaseMapTest { + // [databind#999] + + public static interface Payload999 { } + + @JsonTypeName("foo") + public static class FooPayload999 implements Payload999 { } + + @JsonTypeName("bar") + public static class BarPayload999 implements Payload999 { } + + public static class Message

+ { + final String type; + + @JsonTypeInfo(use = JsonTypeInfo.Id.NAME, + visible = true, + include = JsonTypeInfo.As.EXTERNAL_PROPERTY, property = "type") + @JsonSubTypes({ + @JsonSubTypes.Type(FooPayload999.class), + @JsonSubTypes.Type(BarPayload999.class) }) + final P payload; + + @JsonCreator + public Message(@JsonProperty("type") String type, + @JsonProperty("payload") P payload) + { + this.type = type; + this.payload = payload; + } + } + // [databind#1198] public enum Attacks { KICK, PUNCH } @@ -46,44 +77,30 @@ public Punch(String side) { } } - // [databind#999] - - public static interface Payload999 { } - - @JsonTypeName("foo") - public static class FooPayload999 implements Payload999 { } + /* + /********************************************************************** + /* Test methods + /********************************************************************** + */ - @JsonTypeName("bar") - public static class BarPayload999 implements Payload999 { } + private final ObjectMapper MAPPER = newJsonMapper(); - public static class Message

+ // [databind#999] + public void testExternalTypeId() throws Exception { - final String type; + TypeReference> type = new TypeReference>() { }; - @JsonTypeInfo(use = JsonTypeInfo.Id.NAME, - visible = true, - include = JsonTypeInfo.As.EXTERNAL_PROPERTY, property = "type") - @JsonSubTypes({ - @JsonSubTypes.Type(FooPayload999.class), - @JsonSubTypes.Type(BarPayload999.class) }) - final P payload; + Message msg = MAPPER.readValue(aposToQuotes("{ 'type':'foo', 'payload': {} }"), type); + assertNotNull(msg); + assertNotNull(msg.payload); + assertEquals("foo", msg.type); - @JsonCreator - public Message(@JsonProperty("type") String type, - @JsonProperty("payload") P payload) - { - this.type = type; - this.payload = payload; - } + // and then with different order + msg = MAPPER.readValue(aposToQuotes("{'payload': {}, 'type':'foo' }"), type); + assertNotNull(msg); + assertNotNull(msg.payload); + assertEquals("foo", msg.type); } - - /* - /********************************************************************** - /* Test methods - /********************************************************************** - */ - - private final ObjectMapper MAPPER = new ObjectMapper(); // [databind#1198] public void testFails() throws Exception { @@ -106,21 +123,4 @@ public void testWorks() throws Exception { assertNotNull(character.attack); assertEquals("foo", character.name); } - - // [databind#999] - public void testExternalTypeId() throws Exception - { - TypeReference> type = new TypeReference>() { }; - - Message msg = MAPPER.readValue(aposToQuotes("{ 'type':'foo', 'payload': {} }"), type); - assertNotNull(msg); - assertNotNull(msg.payload); - assertEquals("foo", msg.type); - - // and then with different order - msg = MAPPER.readValue(aposToQuotes("{'payload': {}, 'type':'foo' }"), type); - assertNotNull(msg); - assertNotNull(msg.payload); - assertEquals("foo", msg.type); - } }