Skip to content
This repository was archived by the owner on Jan 20, 2025. It is now read-only.

Commit 40eff79

Browse files
committed
Fix #69
1 parent 24e9150 commit 40eff79

File tree

4 files changed

+21
-4
lines changed

4 files changed

+21
-4
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ Guava (http://code.google.com/p/guava-libraries/) types (currently mostly just c
2929
</contributors>
3030

3131
<properties>
32-
<version.jackson>2.6.0-rc1</version.jackson>
32+
<version.jackson>2.6.0-rc2-SNAPSHOT</version.jackson>
3333

3434
<!-- Generate PackageVersion.java into this directory. -->
3535
<packageVersion.dir>com/fasterxml/jackson/datatype/guava</packageVersion.dir>

release-notes/VERSION

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ Project: jackson-datatype-guava
99
#66: Add `GuavaModule.configureAbsentsAsNulls(boolean)` to change whether
1010
`Optional.absent()` is to be handled same as Java null during serialization
1111
(default: true) or not.
12+
#69: Add support for `JsonInclude.Include.NON_ABSENT`, to compensate for #66
1213

1314
2.5.4 (not yet released)
1415

src/main/java/com/fasterxml/jackson/datatype/guava/GuavaTypeModifier.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,10 @@ public JavaType modifyType(JavaType type, Type jdkType, TypeBindings context, Ty
9999
* Not sure if it'd be with Range; but let's assume it is, for now: sub-classes
100100
* could eliminate/change type parameterization anyway.
101101
*/
102+
// 28-May-2015, tatu: Further, Optional needs to be a ReferenceType
103+
if (target == Optional.class) {
104+
return typeFactory.constructReferenceType(raw, t);
105+
}
102106
return typeFactory.constructParametrizedType(raw, target, t);
103107
}
104108
}

src/test/java/com/fasterxml/jackson/datatype/guava/TestOptional.java

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,9 @@
44

55
import com.fasterxml.jackson.annotation.*;
66
import com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility;
7-
87
import com.fasterxml.jackson.core.type.TypeReference;
9-
8+
import com.fasterxml.jackson.databind.JavaType;
109
import com.fasterxml.jackson.databind.ObjectMapper;
11-
1210
import com.google.common.base.Optional;
1311

1412
public class TestOptional extends ModuleTestBase
@@ -45,6 +43,15 @@ public void link(Unit u) {
4543
/**********************************************************************
4644
*/
4745

46+
public void testOptionalTypeResolution() throws Exception
47+
{
48+
// With 2.6, we need to recognize it as ReferenceType
49+
JavaType t = MAPPER.constructType(Optional.class);
50+
assertNotNull(t);
51+
assertEquals(Optional.class, t.getRawClass());
52+
assertTrue(t.isReferenceType());
53+
}
54+
4855
public void testDeserAbsent() throws Exception {
4956
Optional<?> value = MAPPER.readValue("null", new TypeReference<Optional<String>>() {});
5057
assertFalse(value.isPresent());
@@ -146,7 +153,12 @@ public void testSerOptDisableAsNull() throws Exception {
146153
mapper = new ObjectMapper()
147154
.registerModule(mod)
148155
.setSerializationInclusion(JsonInclude.Include.NON_EMPTY);
156+
assertEquals("{}", mapper.writeValueAsString(data));
149157

158+
// and with new (2.6) NON_ABSENT
159+
mapper = new ObjectMapper()
160+
.registerModule(mod)
161+
.setSerializationInclusion(JsonInclude.Include.NON_ABSENT);
150162
assertEquals("{}", mapper.writeValueAsString(data));
151163
}
152164

0 commit comments

Comments
 (0)