Skip to content

Commit

Permalink
Fix #2573
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Dec 26, 2019
1 parent 32a1c96 commit 8e6c40c
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 46 deletions.
2 changes: 2 additions & 0 deletions release-notes/VERSION-2.x
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ Project: jackson-databind
(reported by Greg A)
#2567: Incorrect target type for arrays when providing nulls and nulls are disabled
(reported by João G)
#2573: Problem with `JsonInclude` config overrides for `java.util.Map`
(reported by SukruthKS@github)
#2576: Fail to serialize `Enum` instance which includes a method override
as POJO (shape = Shape.OBJECT)
(reported by ylhuang-veeva@github)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ public final JsonFormat.Value getDefaultPropertyFormat(Class<?> baseType) {
* @since 2.8
*/
public final JsonInclude.Value getDefaultPropertyInclusion(Class<?> baseType) {
return _config.getDefaultPropertyInclusion();
return _config.getDefaultPropertyInclusion(baseType);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -466,53 +466,53 @@ public JsonSerializer<?> createContextual(SerializerProvider provider,
mser = mser.withFilterId(filterId);
}
}
JsonInclude.Value inclV = property.findPropertyInclusion(provider.getConfig(), null);
if (inclV != null) {
JsonInclude.Include incl = inclV.getContentInclusion();

if (incl != JsonInclude.Include.USE_DEFAULTS) {
Object valueToSuppress;
boolean suppressNulls;
switch (incl) {
case NON_DEFAULT:
valueToSuppress = BeanUtil.getDefaultValue(_valueType);
suppressNulls = true;
if (valueToSuppress != null) {
if (valueToSuppress.getClass().isArray()) {
valueToSuppress = ArrayBuilders.getArrayComparator(valueToSuppress);
}
}
break;
case NON_ABSENT:
suppressNulls = true;
valueToSuppress = _valueType.isReferenceType() ? MARKER_FOR_EMPTY : null;
break;
case NON_EMPTY:
suppressNulls = true;
valueToSuppress = MARKER_FOR_EMPTY;
break;
case CUSTOM:
valueToSuppress = provider.includeFilterInstance(null, inclV.getContentFilter());
if (valueToSuppress == null) { // is this legal?
suppressNulls = true;
} else {
suppressNulls = provider.includeFilterSuppressNulls(valueToSuppress);
}
JsonInclude.Value inclV = findIncludeOverrides(provider, property, Map.class);
if (inclV != null) {
JsonInclude.Include incl = inclV.getContentInclusion();

if (incl != JsonInclude.Include.USE_DEFAULTS) {
Object valueToSuppress;
boolean suppressNulls;
switch (incl) {
case NON_DEFAULT:
valueToSuppress = BeanUtil.getDefaultValue(_valueType);
suppressNulls = true;
if (valueToSuppress != null) {
if (valueToSuppress.getClass().isArray()) {
valueToSuppress = ArrayBuilders.getArrayComparator(valueToSuppress);
}
break;
case NON_NULL:
valueToSuppress = null;
}
break;
case NON_ABSENT:
suppressNulls = true;
valueToSuppress = _valueType.isReferenceType() ? MARKER_FOR_EMPTY : null;
break;
case NON_EMPTY:
suppressNulls = true;
valueToSuppress = MARKER_FOR_EMPTY;
break;
case CUSTOM:
valueToSuppress = provider.includeFilterInstance(null, inclV.getContentFilter());
if (valueToSuppress == null) { // is this legal?
suppressNulls = true;
break;
case ALWAYS: // default
default:
valueToSuppress = null;
// 30-Sep-2016, tatu: Should not need to check global flags here,
// if inclusion forced to be ALWAYS
suppressNulls = false;
break;
} else {
suppressNulls = provider.includeFilterSuppressNulls(valueToSuppress);
}
mser = mser.withContentInclusion(valueToSuppress, suppressNulls);
break;
case NON_NULL:
valueToSuppress = null;
suppressNulls = true;
break;
case ALWAYS: // default
default:
valueToSuppress = null;
// 30-Sep-2016, tatu: Should not need to check global flags here,
// if inclusion forced to be ALWAYS
suppressNulls = false;
break;
}
mser = mser.withContentInclusion(valueToSuppress, suppressNulls);
}
}
return mser;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.fasterxml.jackson.failing;
package com.fasterxml.jackson.databind.ser.filter;

import java.util.*;

Expand Down Expand Up @@ -78,7 +78,7 @@ public void test2572MapOverrideInclAlways() throws Exception
JsonInclude.Include.ALWAYS));
assertEquals(aposToQuotes("{'Speed':100,'Weight':null}"),
mapper.writeValueAsString(CAR_PROPERTIES));
assertEquals(aposToQuotes("{'model':'F60','properties':{'Speed':100,'Weight':null}}}"),
assertEquals(aposToQuotes("{'model':'F60','properties':{'Speed':100,'Weight':null}}"),
mapper.writeValueAsString(CAR));
}
}

0 comments on commit 8e6c40c

Please sign in to comment.