From dc115e0fa98eb235c1ccf74bb23e1e2137bd27fd Mon Sep 17 00:00:00 2001 From: Tatu Saloranta Date: Mon, 24 Nov 2014 17:56:42 -0800 Subject: [PATCH] Add another test for #541 --- .../databind/creators/TestCreators541.java | 109 ++++++++++++++++++ 1 file changed, 109 insertions(+) create mode 100644 src/test/java/com/fasterxml/jackson/databind/creators/TestCreators541.java diff --git a/src/test/java/com/fasterxml/jackson/databind/creators/TestCreators541.java b/src/test/java/com/fasterxml/jackson/databind/creators/TestCreators541.java new file mode 100644 index 0000000000..3c9b7d9353 --- /dev/null +++ b/src/test/java/com/fasterxml/jackson/databind/creators/TestCreators541.java @@ -0,0 +1,109 @@ +package com.fasterxml.jackson.databind.creators; + +import java.util.*; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; + +import com.fasterxml.jackson.databind.*; + +public class TestCreators541 extends BaseMapTest +{ + static final class Foo { + + @JsonProperty("foo") + private Map foo; + @JsonProperty("anumber") + private long anumber; + + public Foo() { + anumber = 0; + } + + public Map getFoo() { + return foo; + } + + public long getAnumber() { + return anumber; + } + } + + static final class Bar { + + private final long p; + private final List stuff; + + @JsonCreator + public Bar(@JsonProperty("p") long p, @JsonProperty("stuff") List stuff) { + this.p = p; + this.stuff = stuff; + } + + @JsonProperty("s") + public List getStuff() { + return stuff; + } + + @JsonProperty("stuff") + private List getStuffDeprecated() { + return stuff; + } + + public long getP() { + return p; + } + } + /* + /********************************************************** + /* Test methods + /********************************************************** + */ + + public void testCreator541() throws Exception + { + ObjectMapper mapper = new ObjectMapper(); + + mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES); + mapper.disable(SerializationFeature.FAIL_ON_EMPTY_BEANS); + mapper.disable( + MapperFeature.AUTO_DETECT_CREATORS, + MapperFeature.AUTO_DETECT_FIELDS, + MapperFeature.AUTO_DETECT_GETTERS, + MapperFeature.AUTO_DETECT_IS_GETTERS, + MapperFeature.AUTO_DETECT_SETTERS, + MapperFeature.USE_GETTERS_AS_SETTERS + ); + mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); + + final String JSON = "{\n" + + " \"foo\": {\n" + + " \"0\": {\n" + + " \"p\": 0,\n" + + " \"stuff\": [\n" + + " \"a\", \"b\" \n" + + " ] \n" + + " },\n" + + " \"1\": {\n" + + " \"p\": 1000,\n" + + " \"stuff\": [\n" + + " \"c\", \"d\" \n" + + " ] \n" + + " },\n" + + " \"2\": {\n" + + " \"p\": 2000,\n" + + " \"stuff\": [\n" + + " ] \n" + + " }\n" + + " },\n" + + " \"anumber\": 25385874\n" + + "}"; + + Foo obj = mapper.readValue(JSON, Foo.class); + assertNotNull(obj); + assertNotNull(obj.foo); + assertEquals(3, obj.foo.size()); + assertEquals(25385874L, obj.getAnumber()); + } +}