Skip to content

Commit

Permalink
Add another test for #541
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Nov 25, 2014
1 parent 6822f33 commit dc115e0
Showing 1 changed file with 109 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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<Integer, Bar> foo;
@JsonProperty("anumber")
private long anumber;

public Foo() {
anumber = 0;
}

public Map<Integer, Bar> getFoo() {
return foo;
}

public long getAnumber() {
return anumber;
}
}

static final class Bar {

private final long p;
private final List<String> stuff;

@JsonCreator
public Bar(@JsonProperty("p") long p, @JsonProperty("stuff") List<String> stuff) {
this.p = p;
this.stuff = stuff;
}

@JsonProperty("s")
public List<String> getStuff() {
return stuff;
}

@JsonProperty("stuff")
private List<String> 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());
}
}

0 comments on commit dc115e0

Please sign in to comment.