Skip to content

Commit 5721b49

Browse files
committed
bit more testing wrt #888
1 parent 5288401 commit 5721b49

File tree

3 files changed

+33
-7
lines changed

3 files changed

+33
-7
lines changed

src/main/java/com/fasterxml/jackson/databind/ser/BasicSerializerFactory.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -869,14 +869,13 @@ protected MapSerializer _checkMapContentInclusion(SerializerProvider prov,
869869
case NON_NULL:
870870
valueToSuppress = null;
871871
suppressNulls = true;
872-
// fall through
872+
break;
873873
case ALWAYS: // default
874874
default:
875875
valueToSuppress = null;
876876
suppressNulls = !prov.isEnabled(SerializationFeature.WRITE_NULL_MAP_VALUES);
877877
break;
878878
}
879-
880879
return mapSer.withContentInclusion(valueToSuppress, suppressNulls);
881880
}
882881

src/main/java/com/fasterxml/jackson/databind/ser/std/MapSerializer.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -281,12 +281,12 @@ public MapSerializer withFilterId(Object filterId) {
281281
* @since 2.9
282282
*/
283283
public MapSerializer withContentInclusion(Object suppressableValue, boolean suppressNulls) {
284-
if ((suppressableValue == _suppressableValue) && (_suppressNulls == suppressNulls)) {
284+
if ((suppressableValue == _suppressableValue) && (suppressNulls == _suppressNulls)) {
285285
return this;
286286
}
287287
_ensureOverride();
288288
return new MapSerializer(this, _valueTypeSerializer, suppressableValue, suppressNulls);
289-
}
289+
}
290290

291291
/**
292292
* @since 2.8
@@ -496,12 +496,12 @@ public JsonSerializer<?> createContextual(SerializerProvider provider,
496496
case NON_NULL:
497497
valueToSuppress = null;
498498
suppressNulls = true;
499-
// fall through
499+
break;
500500
case ALWAYS: // default
501501
default:
502502
valueToSuppress = null;
503-
// 30-Sep-2016, tatu: Should not check global flags here, if inclusion forced
504-
// to be ALWAYS
503+
// 30-Sep-2016, tatu: Should not need to check global flags here,
504+
// if inclusion forced to be ALWAYS
505505
suppressNulls = false;
506506
break;
507507
}

src/test/java/com/fasterxml/jackson/databind/filter/TestMapFiltering.java

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,4 +243,31 @@ public void testMapWithOnlyEmptyValues() throws IOException
243243
.add("b", null)));
244244
assertEquals(aposToQuotes("{}"), json);
245245
}
246+
247+
public void testMapViaGlobalNonEmpty() throws Exception
248+
{
249+
// basic Map<String,String> subclass:
250+
ObjectMapper mapper = new ObjectMapper();
251+
mapper.setPropertyInclusion(JsonInclude.Value.empty()
252+
.withContentInclusion(JsonInclude.Include.NON_EMPTY));
253+
assertEquals(aposToQuotes("{'a':'b'}"), mapper.writeValueAsString(
254+
new StringMap497()
255+
.add("x", "")
256+
.add("a", "b")
257+
));
258+
}
259+
260+
public void testMapViaTypeOverride() throws Exception
261+
{
262+
// basic Map<String,String> subclass:
263+
ObjectMapper mapper = new ObjectMapper();
264+
mapper.configOverride(Map.class)
265+
.setInclude(JsonInclude.Value.empty()
266+
.withContentInclusion(JsonInclude.Include.NON_EMPTY));
267+
assertEquals(aposToQuotes("{'a':'b'}"), mapper.writeValueAsString(
268+
new StringMap497()
269+
.add("foo", "")
270+
.add("a", "b")
271+
));
272+
}
246273
}

0 commit comments

Comments
 (0)