Skip to content

Commit 72740cd

Browse files
committed
Implement #811, support JsonInclude.Include.NON_ABSENT
1 parent 354e139 commit 72740cd

File tree

4 files changed

+23
-2
lines changed

4 files changed

+23
-2
lines changed

pom.xml

+2-2
Original file line numberDiff line numberDiff line change
@@ -69,12 +69,12 @@ javax.xml.datatype, javax.xml.namespace, javax.xml.parsers
6969
<dependency>
7070
<groupId>com.fasterxml.jackson.core</groupId>
7171
<artifactId>jackson-annotations</artifactId>
72-
<version>2.6.0-rc1</version>
72+
<version>2.6.0-rc2-SNAPSHOT</version>
7373
</dependency>
7474
<dependency>
7575
<groupId>com.fasterxml.jackson.core</groupId>
7676
<artifactId>jackson-core</artifactId>
77-
<version>2.6.0-rc1</version>
77+
<version>2.6.0-rc2-SNAPSHOT</version>
7878
</dependency>
7979

8080
<!-- and for testing we need a few libraries

release-notes/VERSION

+2
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ Project: jackson-databind
7474
#801: Using `@JsonCreator` cause generating invalid path reference in `JsonMappingException`
7575
(contributed by Kamil B)
7676
#810: Force value coercion for `java.util.Properties`, so that values are `String`s
77+
#811: Add new option, `JsonInclude.Include.NON_ABSENT` (to support exclusion of
78+
JDK8/Guava Optionals)
7779
- Fix handling of Enums wrt JSON Schema, when 'toString()' used for serialization
7880

7981
2.5.3 (24-Apr-2015)

src/main/java/com/fasterxml/jackson/databind/ser/PropertyBuilder.java

+8
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,14 @@ protected BeanPropertyWriter buildWriter(SerializerProvider prov,
110110
}
111111
}
112112
break;
113+
case NON_ABSENT: // new with 2.6, to support Guava/JDK8 Optionals
114+
// always suppress nulls
115+
suppressNulls = true;
116+
// and for referential types, also "empty", which in their case means "absent"
117+
if (declaredType.isReferenceType()) {
118+
valueToSuppress = BeanPropertyWriter.MARKER_FOR_EMPTY;
119+
}
120+
break;
113121
case NON_EMPTY:
114122
// always suppress nulls
115123
suppressNulls = true;

src/test/java/com/fasterxml/jackson/databind/deser/TestSimpleAtomicTypes.java

+11
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,17 @@ public void testAtomicReference() throws Exception
8484
assertEquals(2, longs[1]);
8585
}
8686

87+
// for [databind#811]
88+
public void testAbsentExclusion() throws Exception
89+
{
90+
ObjectMapper mapper = new ObjectMapper();
91+
mapper.setSerializationInclusion(JsonInclude.Include.NON_ABSENT);
92+
assertEquals(aposToQuotes("{'value':true}"),
93+
mapper.writeValueAsString(new SimpleWrapper(Boolean.TRUE)));
94+
assertEquals(aposToQuotes("{}"),
95+
mapper.writeValueAsString(new SimpleWrapper(null)));
96+
}
97+
8798
// [databind#340]
8899
public void testPolymorphicAtomicReference() throws Exception
89100
{

0 commit comments

Comments
 (0)