Skip to content
This repository has been archived by the owner on Jan 22, 2019. It is now read-only.

Commit

Permalink
Added a test for #37, noting fix requires 2.3.3 of jackson-databind
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Mar 21, 2014
1 parent 7573622 commit c2f772d
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 7 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Guava (http://code.google.com/p/guava-libraries/) types (currently mostly just c
</contributors>

<properties>
<version.jackson>2.3.2</version.jackson>
<version.jackson>2.3.3-SNAPSHOT</version.jackson>

<!-- Generate PackageVersion.java into this directory. -->
<packageVersion.dir>com/fasterxml/jackson/datatype/guava</packageVersion.dir>
Expand Down
2 changes: 2 additions & 0 deletions release-notes/VERSION
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
Project: jackson-datatype-guava
Version: 2.3.3 (xx-xxx-2014)

#37: `Optional` not correctly deserialized from JSON null, if inside a Collection
(reported by JYang-Addepar@github)
#41: `Multimap` serializer does not honor @JsonInclude(JsonInclude.Include.NON_EMPTY)
(reported by Olve S-H)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public Optional<?> deserialize(JsonParser jp, DeserializationContext ctxt) throw
JsonProcessingException
{
Object refd;

if (_valueTypeDeserializer == null) {
refd = _valueDeserializer.deserialize(jp, ctxt);
} else {
Expand Down Expand Up @@ -119,7 +119,6 @@ public Optional<?> deserializeWithType(JsonParser jp, DeserializationContext ctx
return deserialize(jp, ctxt);
}
// with type deserializer to use here? Looks like we get passed same one?
Object ref = typeDeserializer.deserializeTypedFromAny(jp, ctxt);
return Optional.of(ref);
return Optional.of(typeDeserializer.deserializeTypedFromAny(jp, ctxt));
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package com.fasterxml.jackson.datatype.guava;

import java.util.*;

import com.fasterxml.jackson.annotation.*;
import com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility;
import com.fasterxml.jackson.annotation.ObjectIdGenerators;

import com.fasterxml.jackson.core.type.TypeReference;

Expand Down Expand Up @@ -37,7 +38,7 @@ public void link(Unit u) {
baseUnit = Optional.of(u);
}
}

/*
/**********************************************************************
/* Test methods
Expand Down Expand Up @@ -137,7 +138,7 @@ public void testWithTypingEnabled() throws Exception
assertEquals(myData.myString, deserializedMyData.myString);
}

// for [Issue#17]
// [Issue#17]
public void testObjectId() throws Exception
{
final Unit input = new Unit();
Expand All @@ -150,4 +151,26 @@ public void testObjectId() throws Exception
Unit base = result.baseUnit.get();
assertSame(result, base);
}

// [Issue#37]
public void testOptionalCollection() throws Exception {
ObjectMapper mapper = new ObjectMapper().registerModule(new GuavaModule());

TypeReference<List<Optional<String>>> typeReference =
new TypeReference<List<Optional<String>>>() {};

List<Optional<String>> list = new ArrayList<Optional<String>>();
list.add(Optional.of("2014-1-22"));
list.add(Optional.<String>absent());
list.add(Optional.of("2014-1-23"));

String str = mapper.writeValueAsString(list);
assertEquals("[\"2014-1-22\",null,\"2014-1-23\"]", str);

List<Optional<String>> result = mapper.readValue(str, typeReference);
assertEquals(list.size(), result.size());
for (int i = 0; i < list.size(); ++i) {
assertEquals("Entry #"+i, list.get(i), result.get(i));
}
}
}

0 comments on commit c2f772d

Please sign in to comment.