From 90337ecacbeef048e842a6331a3256466d0bd5c9 Mon Sep 17 00:00:00 2001 From: Tatu Saloranta Date: Tue, 1 May 2018 20:58:32 -0700 Subject: [PATCH] Add failing test for #2016 --- .../deser/creators/TestCreators3.java | 16 ++++----- .../creators/TestCreatorsDelegating.java | 35 +++++++++++++++---- 2 files changed, 37 insertions(+), 14 deletions(-) diff --git a/src/test/java/com/fasterxml/jackson/databind/deser/creators/TestCreators3.java b/src/test/java/com/fasterxml/jackson/databind/deser/creators/TestCreators3.java index ca1257ddfc..d00030cb93 100644 --- a/src/test/java/com/fasterxml/jackson/databind/deser/creators/TestCreators3.java +++ b/src/test/java/com/fasterxml/jackson/databind/deser/creators/TestCreators3.java @@ -100,22 +100,22 @@ public String findImplicitPropertyName(AnnotatedMember param) { } // [databind#1853] - public static class Product { + public static class Product1853 { String name; public Object other, errors; @JsonCreator(mode = JsonCreator.Mode.PROPERTIES) - public Product(@JsonProperty("name") String name) { + public Product1853(@JsonProperty("name") String name) { this.name = "PROP:" + name; } @JsonCreator(mode = JsonCreator.Mode.DELEGATING) - public static Product from(String name){ - return new Product(false, "DELEG:"+name); + public static Product1853 from(String name){ + return new Product1853(false, "DELEG:"+name); } - private Product(boolean bogus, String name) { + private Product1853(boolean bogus, String name) { this.name = name; } @@ -193,17 +193,17 @@ public void testMultiCtor421() throws Exception // [databind#1853] public void testSerialization() throws Exception { assertEquals(quote("testProduct"), - MAPPER.writeValueAsString(new Product(false, "testProduct"))); + MAPPER.writeValueAsString(new Product1853(false, "testProduct"))); } public void testDeserializationFromObject() throws Exception { final String EXAMPLE_DATA = "{\"name\":\"dummy\",\"other\":{},\"errors\":{}}"; - assertEquals("PROP:dummy", MAPPER.readValue(EXAMPLE_DATA, Product.class).getName()); + assertEquals("PROP:dummy", MAPPER.readValue(EXAMPLE_DATA, Product1853.class).getName()); } public void testDeserializationFromString() throws Exception { assertEquals("DELEG:testProduct", - MAPPER.readValue(quote("testProduct"), Product.class).getName()); + MAPPER.readValue(quote("testProduct"), Product1853.class).getName()); } } diff --git a/src/test/java/com/fasterxml/jackson/databind/deser/creators/TestCreatorsDelegating.java b/src/test/java/com/fasterxml/jackson/databind/deser/creators/TestCreatorsDelegating.java index aca376674c..692607fe51 100644 --- a/src/test/java/com/fasterxml/jackson/databind/deser/creators/TestCreatorsDelegating.java +++ b/src/test/java/com/fasterxml/jackson/databind/deser/creators/TestCreatorsDelegating.java @@ -1,15 +1,15 @@ package com.fasterxml.jackson.databind.deser.creators; -import com.fasterxml.jackson.annotation.JsonCreator; - -import java.util.Map; +import java.util.*; import com.fasterxml.jackson.annotation.JacksonInject; +import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.core.JsonParser; import com.fasterxml.jackson.core.JsonToken; import com.fasterxml.jackson.databind.*; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; import com.fasterxml.jackson.databind.util.TokenBuffer; public class TestCreatorsDelegating extends BaseMapTest @@ -82,14 +82,28 @@ public MapBean(Map map) { this.map = map; } } - + + // [databind#2016] + static class Wrapper2016 { + private final List value; + + @JsonCreator //(mode = JsonCreator.Mode.DELEGATING) + public Wrapper2016(@JsonDeserialize(as = LinkedList.class) List value) { + this.value = value; + } + + public List getValue() { + return value; + } + } + /* /********************************************************** - /* Unit tests + /* Test methods /********************************************************** */ - private final ObjectMapper MAPPER = new ObjectMapper(); + private final ObjectMapper MAPPER = newObjectMapper(); public void testBooleanDelegate() throws Exception { @@ -180,4 +194,13 @@ public void testIssue465() throws Exception bean = MAPPER.readValue(EMPTY_JSON, MapBean.class); assertEquals(0, bean.map.size()); } + + // [databind#2016] + public void testCreatorWithDeserializeAs2016() throws Exception + { + String json = "[\"Hello, World!\"]"; + Wrapper2016 actual = MAPPER.readValue(json, Wrapper2016.class); + assertEquals(Collections.singletonList("Hello, World!"), actual.getValue()); + assertEquals(LinkedList.class, actual.getValue().getClass()); + } }