Skip to content

Commit

Permalink
Fix #1124
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Feb 27, 2016
1 parent 6ec5136 commit 4eba399
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 18 deletions.
4 changes: 4 additions & 0 deletions release-notes/CREDITS
Original file line number Diff line number Diff line change
Expand Up @@ -422,3 +422,7 @@ Aleks Seovic (aseovic@github)
Timur Shakurov (saladinkzn@github)
* Reported #1134: Jackson 2.7 doesn't work with jdk6 due to use of `Collections.emptyIterator()`
(2.7.2)

Jiri Mikulasek (pirkogdc@github)
* Reported #1124: JsonAnyGetter ignores JsonSerialize(contentUsing=...)
(2.7.2)
2 changes: 2 additions & 0 deletions release-notes/VERSION
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ Project: jackson-databind

2.7.2 (not released yet)

#1124: JsonAnyGetter ignores JsonSerialize(contentUsing=...)
(reported by Jiri M)
#1128: UnrecognizedPropertyException in 2.7.1 for properties that work with version 2.6.5
(reported by Roleek@github)
#1129: When applying type modifiers, don't ignore container types.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -677,7 +677,7 @@ protected SettableAnyProperty constructAnySetter(DeserializationContext ctxt,
PropertyMetadata.STD_OPTIONAL);
type = resolveType(ctxt, beanDesc, type, setter);

/* AnySetter can be annotated with @JsonClass (etc) just like a
/* AnySetter can be annotated with @JsonDeserialize (etc) just like a
* regular setter... so let's see if those are used.
* Returns null if no annotations, in which case binding will
* be done at a later point.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,7 @@ public JsonSerializer<?> createContextual(SerializerProvider provider,
ser = provider.serializerInstance(propertyAcc, serDef);
}
}

if (property != null) {
JsonInclude.Value inclV = property.findPropertyInclusion(provider.getConfig(), Map.class);
JsonInclude.Include incl = inclV.getContentInclusion();
Expand Down Expand Up @@ -557,13 +558,14 @@ public void serializeWithType(Map<?,?> value, JsonGenerator gen, SerializerProvi

/*
/**********************************************************
/* JsonSerializer implementation
/* Secondary serialization methods
/**********************************************************
*/

/**
* Method called to serialize fields, when the value type is not statically known;
* but we know that no value suppression is needed (which simplifies processing a bit)
* General-purpose serialization for contents, where we do not necessarily know
* the value serialization, but
* we do know that no value suppression is needed (which simplifies processing a bit)
*/
public void serializeFields(Map<?,?> value, JsonGenerator gen, SerializerProvider provider)
throws IOException
Expand Down Expand Up @@ -594,9 +596,12 @@ public void serializeFields(Map<?,?> value, JsonGenerator gen, SerializerProvide
// And then value
if (valueElem == null) {
provider.defaultSerializeNull(gen);
} else {
continue;
}
JsonSerializer<Object> serializer = _valueSerializer;
if (serializer == null) {
Class<?> cc = valueElem.getClass();
JsonSerializer<Object> serializer = serializers.serializerFor(cc);
serializer = serializers.serializerFor(cc);
if (serializer == null) {
if (_valueType.hasGenericTypes()) {
serializer = _findAndAddDynamic(serializers,
Expand All @@ -606,13 +611,13 @@ public void serializeFields(Map<?,?> value, JsonGenerator gen, SerializerProvide
}
serializers = _dynamicValueSerializers;
}
try {
serializer.serialize(valueElem, gen, provider);
} catch (Exception e) {
// Add reference information
String keyDesc = ""+keyElem;
wrapAndThrow(provider, e, value, keyDesc);
}
}
try {
serializer.serialize(valueElem, gen, provider);
} catch (Exception e) {
// Add reference information
String keyDesc = ""+keyElem;
wrapAndThrow(provider, e, value, keyDesc);
}
}
}
Expand Down Expand Up @@ -688,7 +693,7 @@ public void serializeOptionalFields(Map<?,?> value, JsonGenerator gen, Serialize
* so that value serializer is passed and does not need to be fetched from
* provider.
*/
protected void serializeFieldsUsing(Map<?,?> value, JsonGenerator gen, SerializerProvider provider,
public void serializeFieldsUsing(Map<?,?> value, JsonGenerator gen, SerializerProvider provider,
JsonSerializer<Object> ser)
throws IOException
{
Expand Down Expand Up @@ -738,7 +743,7 @@ public void serializeFilteredFields(Map<?,?> value, JsonGenerator gen, Serialize

PropertySerializerMap serializers = _dynamicValueSerializers;
final MapProperty prop = new MapProperty(_valueTypeSerializer, _property);

for (Map.Entry<?,?> entry : value.entrySet()) {
// First, serialize key; unless ignorable by key
final Object keyElem = entry.getKey();
Expand Down Expand Up @@ -802,7 +807,7 @@ public void serializeFilteredFields(Map<?,?> value, JsonGenerator gen, Serialize
/**
* @since 2.5
*/
protected void serializeTypedFields(Map<?,?> value, JsonGenerator gen, SerializerProvider provider,
public void serializeTypedFields(Map<?,?> value, JsonGenerator gen, SerializerProvider provider,
Object suppressableValue) // since 2.5
throws IOException
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public MapBean() {
}
}

static class MyMapFilter implements PropertyFilter
static class TestMapFilter implements PropertyFilter
{
@Override
public void serializeAsField(Object value, JsonGenerator jgen,
Expand Down Expand Up @@ -176,7 +176,7 @@ public void testNonNullValueMapViaProp() throws IOException
public void testMapFilteringWithAnnotations() throws Exception
{
FilterProvider prov = new SimpleFilterProvider().addFilter("filterX",
new MyMapFilter());
new TestMapFilter());
String json = MAPPER.writer(prov).writeValueAsString(new MapBean());
// a=1 should become a=2
assertEquals(aposToQuotes("{'values':{'a':2}}"), json);
Expand Down

0 comments on commit 4eba399

Please sign in to comment.