-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6822f33
commit dc115e0
Showing
1 changed file
with
109 additions
and
0 deletions.
There are no files selected for viewing
109 changes: 109 additions & 0 deletions
109
src/test/java/com/fasterxml/jackson/databind/creators/TestCreators541.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
} | ||
} |