Skip to content

Commit

Permalink
more work on supporting Map/include values
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Oct 20, 2014
1 parent c2892f9 commit 2705b17
Show file tree
Hide file tree
Showing 5 changed files with 179 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ public void getAndFilter(Object bean, JsonGenerator jgen, SerializerProvider pro
throw new JsonMappingException("Value returned by 'any-getter' ("
+_accessor.getName()+"()) not java.util.Map but "+value.getClass().getName());
}
_serializer.serializeFilteredFields((Map<?,?>) value, jgen, provider, filter);
// 19-Oct-2014, tatu: Should we try to support @JsonInclude options here?
_serializer.serializeFilteredFields((Map<?,?>) value, jgen, provider, filter, null);
}

// Note: NOT part of ResolvableSerializer...
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import java.util.*;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonInclude;

import com.fasterxml.jackson.databind.*;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.cfg.SerializerFactoryConfig;
Expand All @@ -20,10 +22,7 @@
import com.fasterxml.jackson.databind.ser.impl.*;
import com.fasterxml.jackson.databind.ser.std.*;
import com.fasterxml.jackson.databind.type.*;
import com.fasterxml.jackson.databind.util.ClassUtil;
import com.fasterxml.jackson.databind.util.Converter;
import com.fasterxml.jackson.databind.util.EnumValues;
import com.fasterxml.jackson.databind.util.TokenBuffer;
import com.fasterxml.jackson.databind.util.*;

/**
* Factory class that can provide serializers for standard JDK classes,
Expand Down Expand Up @@ -735,9 +734,15 @@ protected JsonSerializer<?> buildMapSerializer(SerializationConfig config,
elementTypeSerializer, elementValueSerializer);
} else {
Object filterId = findFilterId(config, beanDesc);
ser = MapSerializer.construct(config.getAnnotationIntrospector().findPropertiesToIgnore(beanDesc.getClassInfo()),
MapSerializer mapSer = MapSerializer.construct(config.getAnnotationIntrospector().findPropertiesToIgnore(beanDesc.getClassInfo()),
type, staticTyping, elementTypeSerializer,
keySerializer, elementValueSerializer, filterId);
Object suppressableValue = findSuppressableContentValue(config,
type.getContentType(), beanDesc);
if (suppressableValue != null) {
mapSer = mapSer.withContentInclusion(suppressableValue);
}
ser = mapSer;
}
}
// [Issue#120]: Allow post-processing
Expand All @@ -749,6 +754,30 @@ protected JsonSerializer<?> buildMapSerializer(SerializationConfig config,
return ser;
}

/**
* @since 2.5
*/
protected Object findSuppressableContentValue(SerializationConfig config,
JavaType contentType, BeanDescription beanDesc)
throws JsonMappingException
{
JsonInclude.Include incl = beanDesc.findSerializationInclusionForContent(null);

if (incl != null) {
switch (incl) {
case NON_DEFAULT:
// 19-Oct-2014, tatu: Not sure what this'd mean; so take it to mean "NON_EMPTY"...
incl = JsonInclude.Include.NON_EMPTY;
break;
default:
// all other modes actually good as is, unless we'll find better ways
break;
}
return incl;
}
return null;
}

/*
/**********************************************************
/* Factory methods, for Arrays
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import java.lang.reflect.Type;
import java.util.HashMap;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.core.SerializableString;
import com.fasterxml.jackson.core.io.SerializedString;
Expand Down Expand Up @@ -37,8 +38,8 @@ public class BeanPropertyWriter extends PropertyWriter
/**
* Marker object used to indicate "do not serialize if empty"
*/
public final static Object MARKER_FOR_EMPTY = new Object();
public final static Object MARKER_FOR_EMPTY = JsonInclude.Include.NON_EMPTY;

/*
/**********************************************************
/* Settings for accessing property value to serialize
Expand Down
Loading

0 comments on commit 2705b17

Please sign in to comment.