-
-
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
b53fa57
commit 32a1c96
Showing
1 changed file
with
84 additions
and
0 deletions.
There are no files selected for viewing
84 changes: 84 additions & 0 deletions
84
src/test/java/com/fasterxml/jackson/failing/MapInclusion2573Test.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,84 @@ | ||
package com.fasterxml.jackson.failing; | ||
|
||
import java.util.*; | ||
|
||
import com.fasterxml.jackson.annotation.JsonInclude; | ||
import com.fasterxml.jackson.annotation.JsonPropertyOrder; | ||
import com.fasterxml.jackson.databind.*; | ||
import com.fasterxml.jackson.databind.json.JsonMapper; | ||
|
||
public class MapInclusion2573Test extends BaseMapTest | ||
{ | ||
@JsonPropertyOrder({ "model", "properties" }) | ||
static class Car | ||
{ | ||
public String model; | ||
public Map<String, Integer> properties; | ||
} | ||
|
||
/* | ||
/********************************************************** | ||
/* Test methods | ||
/********************************************************** | ||
*/ | ||
|
||
private final Map<String, Integer> CAR_PROPERTIES = new LinkedHashMap<>(); | ||
{ | ||
CAR_PROPERTIES.put("Speed", 100); | ||
CAR_PROPERTIES.put("Weight", null); | ||
} | ||
|
||
private final Car CAR = new Car(); | ||
{ | ||
CAR.model = "F60"; | ||
CAR.properties = CAR_PROPERTIES; | ||
} | ||
|
||
private final JsonInclude.Value BOTH_NON_NULL = JsonInclude.Value.construct(JsonInclude.Include.NON_NULL, | ||
JsonInclude.Include.NON_NULL); | ||
|
||
// final private ObjectMapper MAPPER = objectMapper(); | ||
|
||
// [databind#2572] | ||
public void test2572MapDefault() throws Exception | ||
{ | ||
|
||
ObjectMapper mapper = JsonMapper.builder() | ||
.defaultPropertyInclusion(BOTH_NON_NULL) | ||
.build(); | ||
assertEquals(aposToQuotes("{'Speed':100}"), | ||
mapper.writeValueAsString(CAR_PROPERTIES)); | ||
assertEquals(aposToQuotes("{'model':'F60','properties':{'Speed':100}}"), | ||
mapper.writeValueAsString(CAR)); | ||
} | ||
|
||
// [databind#2572] | ||
public void test2572MapOverrideUseDefaults() throws Exception | ||
{ | ||
ObjectMapper mapper = JsonMapper.builder() | ||
.defaultPropertyInclusion(BOTH_NON_NULL) | ||
.build(); | ||
mapper.configOverride(Map.class) | ||
.setInclude(JsonInclude.Value.construct(JsonInclude.Include.USE_DEFAULTS, | ||
JsonInclude.Include.USE_DEFAULTS)); | ||
assertEquals(aposToQuotes("{'Speed':100}"), | ||
mapper.writeValueAsString(CAR_PROPERTIES)); | ||
assertEquals(aposToQuotes("{'model':'F60','properties':{'Speed':100}}"), | ||
mapper.writeValueAsString(CAR)); | ||
} | ||
|
||
// [databind#2572] | ||
public void test2572MapOverrideInclAlways() throws Exception | ||
{ | ||
ObjectMapper mapper = JsonMapper.builder() | ||
.defaultPropertyInclusion(BOTH_NON_NULL) | ||
.build(); | ||
mapper.configOverride(Map.class) | ||
.setInclude(JsonInclude.Value.construct(JsonInclude.Include.ALWAYS, | ||
JsonInclude.Include.ALWAYS)); | ||
assertEquals(aposToQuotes("{'Speed':100,'Weight':null}"), | ||
mapper.writeValueAsString(CAR_PROPERTIES)); | ||
assertEquals(aposToQuotes("{'model':'F60','properties':{'Speed':100,'Weight':null}}}"), | ||
mapper.writeValueAsString(CAR)); | ||
} | ||
} |