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

Commit

Permalink
Eclipse warnings cleanup; adding a unit test trying to reproduce #29,…
Browse files Browse the repository at this point in the history
… failing so far
  • Loading branch information
cowtowncoder committed Oct 20, 2013
1 parent 3de101e commit e01df0a
Show file tree
Hide file tree
Showing 20 changed files with 85 additions and 52 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ public abstract class GuavaCollectionDeserializer<T>
extends StdDeserializer<T>
implements ContextualDeserializer
{
private static final long serialVersionUID = 1L;

protected final CollectionType _containerType;

/**
Expand Down Expand Up @@ -56,6 +58,7 @@ public abstract GuavaCollectionDeserializer<T> withResolved(
* after deserializer itself has been registered. This
* is needed to handle recursive and transitive dependencies.
*/
@Override
public JsonDeserializer<?> createContextual(DeserializationContext ctxt,
BeanProperty property) throws JsonMappingException
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@
import com.google.common.collect.ImmutableCollection;

abstract class GuavaImmutableCollectionDeserializer<T extends ImmutableCollection<Object>>
extends GuavaCollectionDeserializer<T> {
extends GuavaCollectionDeserializer<T>
{
private static final long serialVersionUID = 1L;

GuavaImmutableCollectionDeserializer(CollectionType type,
TypeDeserializer typeDeser, JsonDeserializer<?> deser) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ public abstract GuavaMapDeserializer<T> withResolved(KeyDeserializer keyDeser,
* after deserializer itself has been registered. This
* is needed to handle recursive and transitive dependencies.
*/
@Override
public JsonDeserializer<?> createContextual(DeserializationContext ctxt,
BeanProperty property) throws JsonMappingException
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
import com.fasterxml.jackson.databind.type.CollectionType;
import com.google.common.collect.Multiset;

abstract class GuavaMultisetDeserializer<T extends Multiset<Object>> extends GuavaCollectionDeserializer<T> {
abstract class GuavaMultisetDeserializer<T extends Multiset<Object>> extends GuavaCollectionDeserializer<T>
{
private static final long serialVersionUID = 1L;

GuavaMultisetDeserializer(CollectionType type, TypeDeserializer typeDeser, JsonDeserializer<?> deser) {
super(type, typeDeser, deser);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@
import com.fasterxml.jackson.databind.jsontype.TypeDeserializer;
import com.google.common.base.Optional;

public final class GuavaOptionalDeserializer extends StdDeserializer<Optional<?>> {
public final class GuavaOptionalDeserializer extends StdDeserializer<Optional<?>>
{
private static final long serialVersionUID = 1L;

private final JavaType _referenceType;

public GuavaOptionalDeserializer(JavaType valueType) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@
import com.google.common.collect.HashMultiset;

public class HashMultisetDeserializer
extends GuavaMultisetDeserializer<HashMultiset<Object>>
extends GuavaMultisetDeserializer<HashMultiset<Object>>
{
private static final long serialVersionUID = 1L;

public HashMultisetDeserializer(CollectionType type,
TypeDeserializer typeDeser, JsonDeserializer<?> deser)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@
import com.fasterxml.jackson.databind.type.CollectionType;

public class ImmutableListDeserializer extends
GuavaImmutableCollectionDeserializer<ImmutableList<Object>> {
GuavaImmutableCollectionDeserializer<ImmutableList<Object>>
{
private static final long serialVersionUID = 1L;

public ImmutableListDeserializer(CollectionType type,
TypeDeserializer typeDeser, JsonDeserializer<?> deser) {
super(type, typeDeser, deser);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
import com.google.common.collect.ImmutableCollection.Builder;
import com.google.common.collect.ImmutableMultiset;

public class ImmutableMultisetDeserializer extends GuavaImmutableCollectionDeserializer<ImmutableMultiset<Object>> {
public class ImmutableMultisetDeserializer extends GuavaImmutableCollectionDeserializer<ImmutableMultiset<Object>>
{
private static final long serialVersionUID = 1L;

public ImmutableMultisetDeserializer(CollectionType type, TypeDeserializer typeDeser, JsonDeserializer<?> deser) {
super(type, typeDeser, deser);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

public class ImmutableSetDeserializer extends GuavaImmutableCollectionDeserializer<ImmutableSet<Object>>
{
private static final long serialVersionUID = 1L;

public ImmutableSetDeserializer(CollectionType type,
TypeDeserializer typeDeser, JsonDeserializer<?> deser)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

public class ImmutableSortedSetDeserializer extends GuavaImmutableCollectionDeserializer<ImmutableSortedSet<Object>>
{
private static final long serialVersionUID = 1L;

public ImmutableSortedSetDeserializer(CollectionType type,
TypeDeserializer typeDeser, JsonDeserializer<?> deser)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
import com.fasterxml.jackson.databind.type.CollectionType;
import com.google.common.collect.LinkedHashMultiset;

public class LinkedHashMultisetDeserializer extends GuavaMultisetDeserializer<LinkedHashMultiset<Object>> {
public class LinkedHashMultisetDeserializer extends GuavaMultisetDeserializer<LinkedHashMultiset<Object>>
{
private static final long serialVersionUID = 1L;

public LinkedHashMultisetDeserializer(CollectionType type, TypeDeserializer typeDeser, JsonDeserializer<?> deser) {
super(type, typeDeser, deser);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
import com.fasterxml.jackson.databind.type.CollectionType;
import com.google.common.collect.TreeMultiset;

public class TreeMultisetDeserializer extends GuavaMultisetDeserializer<TreeMultiset<Object>> {
public class TreeMultisetDeserializer extends GuavaMultisetDeserializer<TreeMultiset<Object>>
{
private static final long serialVersionUID = 1L;

public TreeMultisetDeserializer(CollectionType type, TypeDeserializer typeDeser, JsonDeserializer<?> deser) {
super(type, typeDeser, deser);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ private static Method findTransformer(Class<?> rawType) {
* We need to use this method to properly handle possible contextual variants of key and value
* deserializers, as well as type deserializers.
*/
@Override
public JsonDeserializer<?> createContextual(DeserializationContext ctxt,
BeanProperty property) throws JsonMappingException {
KeyDeserializer kd = keyDeserializer;
Expand All @@ -117,7 +118,7 @@ public JsonDeserializer<?> createContextual(DeserializationContext ctxt,

protected abstract JsonDeserializer<?> _createContextual(MapLikeType type,
KeyDeserializer keyDeserializer, TypeDeserializer typeDeserializer,
JsonDeserializer elementDeserializer, Method method);
JsonDeserializer<?> elementDeserializer, Method method);

@Override
public T deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ protected ArrayListMultimap<Object, Object> createMultimap() {
@Override
protected JsonDeserializer<?> _createContextual(MapLikeType type,
KeyDeserializer keyDeserializer, TypeDeserializer typeDeserializer,
JsonDeserializer elementDeserializer, Method method) {
JsonDeserializer<?> elementDeserializer, Method method) {
return new ArrayListMultimapDeserializer(type, keyDeserializer, typeDeserializer,
elementDeserializer, method);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
*
* @author mvolkhart
*/
public class LinkedListMultimapDeserializer extends GuavaMultimapDeserializer<LinkedListMultimap<Object,
Object>> {

public class LinkedListMultimapDeserializer
extends GuavaMultimapDeserializer<LinkedListMultimap<Object,Object>>
{
public LinkedListMultimapDeserializer(MapLikeType type, KeyDeserializer keyDeserializer,
TypeDeserializer elementTypeDeserializer, JsonDeserializer<?> elementDeserializer) {
super(type, keyDeserializer, elementTypeDeserializer, elementDeserializer);
Expand All @@ -36,7 +36,7 @@ protected LinkedListMultimap<Object, Object> createMultimap() {
@Override
protected JsonDeserializer<?> _createContextual(MapLikeType type,
KeyDeserializer keyDeserializer, TypeDeserializer typeDeserializer,
JsonDeserializer elementDeserializer, Method method) {
JsonDeserializer<?> elementDeserializer, Method method) {
return new LinkedListMultimapDeserializer(type, keyDeserializer, typeDeserializer,
elementDeserializer, method);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ protected HashMultimap<Object, Object> createMultimap() {
@Override
protected JsonDeserializer<?> _createContextual(MapLikeType type,
KeyDeserializer keyDeserializer, TypeDeserializer typeDeserializer,
JsonDeserializer elementDeserializer, Method method) {
JsonDeserializer<?> elementDeserializer, Method method) {
return new HashMultimapDeserializer(type, keyDeserializer, typeDeserializer,
elementDeserializer, method);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ protected LinkedHashMultimap<Object, Object> createMultimap() {
@Override
protected JsonDeserializer<?> _createContextual(MapLikeType type,
KeyDeserializer keyDeserializer, TypeDeserializer typeDeserializer,
JsonDeserializer elementDeserializer, Method method) {
JsonDeserializer<?> elementDeserializer, Method method) {
return new LinkedHashMultimapDeserializer(type, keyDeserializer, typeDeserializer,
elementDeserializer, method);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ public class MultimapSerializer
extends JsonSerializer<Multimap<?, ?>>
implements ContextualSerializer
{
private final MapLikeType type;
private final BeanProperty property;
private final JsonSerializer<Object> keySerializer;
private final TypeSerializer valueTypeSerializer;
private final JsonSerializer<Object> valueSerializer;
private final MapLikeType _type;
private final BeanProperty _property;
private final JsonSerializer<Object> _keySerializer;
private final TypeSerializer _valueTypeSerializer;
private final JsonSerializer<Object> _valueSerializer;

public MultimapSerializer(SerializationConfig config,
MapLikeType type,
Expand All @@ -31,32 +31,30 @@ public MultimapSerializer(SerializationConfig config,
TypeSerializer valueTypeSerializer,
JsonSerializer<Object> valueSerializer)
{
this.type = type;
this.property = null;
this.keySerializer = keySerializer;
this.valueTypeSerializer = valueTypeSerializer;
this.valueSerializer = valueSerializer;
_type = type;
_property = null;
_keySerializer = keySerializer;
_valueTypeSerializer = valueTypeSerializer;
_valueSerializer = valueSerializer;
}

@SuppressWarnings("unchecked")
protected MultimapSerializer(MultimapSerializer src, BeanProperty property,
JsonSerializer<?> keySerializer,
TypeSerializer valueTypeSerializer, JsonSerializer<?> valueSerializer)
{
this.type = src.type;
this.property = property;
this.keySerializer = (JsonSerializer<Object>) keySerializer;
this.valueTypeSerializer = valueTypeSerializer;
this.valueSerializer = (JsonSerializer<Object>) valueSerializer;
_type = src._type;
_property = property;
_keySerializer = (JsonSerializer<Object>) keySerializer;
_valueTypeSerializer = valueTypeSerializer;
_valueSerializer = (JsonSerializer<Object>) valueSerializer;
}



protected MultimapSerializer withResolved(BeanProperty property,
JsonSerializer<?> keySerializer,
TypeSerializer valueTypeSerializer, JsonSerializer<?> valueSerializer)
JsonSerializer<?> keySer,
TypeSerializer vts, JsonSerializer<?> valueSer)
{
return new MultimapSerializer(this, property, keySerializer,
valueTypeSerializer, valueSerializer);
return new MultimapSerializer(this, property, keySer, vts, valueSer);
}

/*
Expand All @@ -65,26 +63,27 @@ protected MultimapSerializer withResolved(BeanProperty property,
/**********************************************************
*/

@Override
public JsonSerializer<?> createContextual(SerializerProvider provider,
BeanProperty property) throws JsonMappingException
{
JsonSerializer<?> valueSer = valueSerializer;
JsonSerializer<?> valueSer = _valueSerializer;
if (valueSer == null) { // if type is final, can actually resolve:
JavaType valueType = type.getContentType();
JavaType valueType = _type.getContentType();
if (valueType.isFinal()) {
valueSer = provider.findValueSerializer(valueType, property);
}
} else if (valueSer instanceof ContextualSerializer) {
valueSer = ((ContextualSerializer) valueSer).createContextual(provider, property);
}
JsonSerializer<?> keySer = keySerializer;
JsonSerializer<?> keySer = _keySerializer;
if (keySer == null) {
keySer = provider.findKeySerializer(type.getKeyType(), property);
keySer = provider.findKeySerializer(_type.getKeyType(), property);
} else if (keySer instanceof ContextualSerializer) {
keySer = ((ContextualSerializer) keySer).createContextual(provider, property);
}
// finally, TypeSerializers may need contextualization as well
TypeSerializer typeSer = valueTypeSerializer;
TypeSerializer typeSer = _valueTypeSerializer;
if (typeSer != null) {
typeSer = typeSer.forProperty(property);
}
Expand Down Expand Up @@ -122,17 +121,17 @@ private final void serializeFields(Multimap<?, ?> value, JsonGenerator jgen, Ser
throws IOException, JsonProcessingException
{
for (Entry<?, ? extends Collection<?>> e : value.asMap().entrySet()) {
if (keySerializer != null) {
keySerializer.serialize(e.getKey(), jgen, provider);
if (_keySerializer != null) {
_keySerializer.serialize(e.getKey(), jgen, provider);
} else {
provider.findKeySerializer(provider.constructType(String.class), property)
provider.findKeySerializer(provider.constructType(String.class), _property)
.serialize(e.getKey(), jgen, provider);
}
if (valueSerializer != null) {
if (_valueSerializer != null) {
// note: value is a List, but generic type is for contents... so:
jgen.writeStartArray();
for (Object vv : e.getValue()) {
valueSerializer.serialize(vv, jgen, provider);
_valueSerializer.serialize(vv, jgen, provider);
}
jgen.writeEndArray();
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@
import java.util.Iterator;

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

import com.fasterxml.jackson.databind.JavaType;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.ObjectMapper;

import com.google.common.collect.*;

/**
Expand Down Expand Up @@ -122,10 +121,16 @@ public void testImmutableSortedSet() throws Exception
public void testImmutableMap() throws Exception
{
ObjectMapper mapper = mapperWithModule();
ImmutableMap<Integer,Boolean> map = mapper.readValue("{\"12\":true,\"4\":false}", new TypeReference<ImmutableMap<Integer,Boolean>>() { });
final JavaType type = mapper.getTypeFactory().constructType(new TypeReference<ImmutableMap<Integer,Boolean>>() { });
ImmutableMap<Integer,Boolean> map = mapper.readValue("{\"12\":true,\"4\":false}", type);
assertEquals(2, map.size());
assertEquals(Boolean.TRUE, map.get(Integer.valueOf(12)));
assertEquals(Boolean.FALSE, map.get(Integer.valueOf(4)));

// [Issue#29]
map = mapper.readValue("{}", type);
assertNotNull(map);
assertEquals(0, map.size());
}

public void testImmutableSortedMap() throws Exception
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,9 @@ public void testForwardingSetMultimap() {

}

private SetMultimap<String, String> setBasedHelper(TypeReference type) throws IOException {
private SetMultimap<String, String> setBasedHelper(TypeReference<?> type)
throws IOException
{
SetMultimap<String, String> map = MAPPER.readValue(StringStringMultimap, type);
assertEquals(3, map.size());
assertTrue(map.containsEntry("first", "abc"));
Expand Down Expand Up @@ -183,7 +185,7 @@ public void testLinkedListMultimap() throws IOException {
assertTrue(map instanceof LinkedListMultimap);
}

private ListMultimap<String, String> listBasedHelper(TypeReference type) throws IOException {
private ListMultimap<String, String> listBasedHelper(TypeReference<?> type) throws IOException {
ListMultimap<String, String> map = MAPPER.readValue(StringStringMultimap, type);
assertEquals(4, map.size());
assertTrue(map.remove("first", "abc"));
Expand Down

0 comments on commit e01df0a

Please sign in to comment.