diff options
author | Tatu Saloranta <tatu.saloranta@iki.fi> | 2016-09-30 19:27:28 -0700 |
---|---|---|
committer | Tatu Saloranta <tatu.saloranta@iki.fi> | 2016-09-30 19:27:28 -0700 |
commit | 5721b491d47f66f1953690552be3001d6b9a069f (patch) | |
tree | e3d7f1723a05d58b6a90acd626a468a2933cc6ac | |
parent | 528840141dc8b6323c897d7d39de389dc164b194 (diff) | |
download | jackson-databind-5721b491d47f66f1953690552be3001d6b9a069f.tar.gz |
bit more testing wrt #888
3 files changed, 33 insertions, 7 deletions
diff --git a/src/main/java/com/fasterxml/jackson/databind/ser/BasicSerializerFactory.java b/src/main/java/com/fasterxml/jackson/databind/ser/BasicSerializerFactory.java index de92c5155..2f24f7313 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ser/BasicSerializerFactory.java +++ b/src/main/java/com/fasterxml/jackson/databind/ser/BasicSerializerFactory.java @@ -869,14 +869,13 @@ public abstract class BasicSerializerFactory case NON_NULL: valueToSuppress = null; suppressNulls = true; - // fall through + break; case ALWAYS: // default default: valueToSuppress = null; suppressNulls = !prov.isEnabled(SerializationFeature.WRITE_NULL_MAP_VALUES); break; } - return mapSer.withContentInclusion(valueToSuppress, suppressNulls); } diff --git a/src/main/java/com/fasterxml/jackson/databind/ser/std/MapSerializer.java b/src/main/java/com/fasterxml/jackson/databind/ser/std/MapSerializer.java index 3da9858b5..c2fb3ecb5 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ser/std/MapSerializer.java +++ b/src/main/java/com/fasterxml/jackson/databind/ser/std/MapSerializer.java @@ -281,12 +281,12 @@ public class MapSerializer * @since 2.9 */ public MapSerializer withContentInclusion(Object suppressableValue, boolean suppressNulls) { - if ((suppressableValue == _suppressableValue) && (_suppressNulls == suppressNulls)) { + if ((suppressableValue == _suppressableValue) && (suppressNulls == _suppressNulls)) { return this; } _ensureOverride(); return new MapSerializer(this, _valueTypeSerializer, suppressableValue, suppressNulls); - } + } /** * @since 2.8 @@ -496,12 +496,12 @@ public class MapSerializer case NON_NULL: valueToSuppress = null; suppressNulls = true; - // fall through + break; case ALWAYS: // default default: valueToSuppress = null; - // 30-Sep-2016, tatu: Should not check global flags here, if inclusion forced - // to be ALWAYS + // 30-Sep-2016, tatu: Should not need to check global flags here, + // if inclusion forced to be ALWAYS suppressNulls = false; break; } diff --git a/src/test/java/com/fasterxml/jackson/databind/filter/TestMapFiltering.java b/src/test/java/com/fasterxml/jackson/databind/filter/TestMapFiltering.java index b7068fba1..f1f83ee74 100644 --- a/src/test/java/com/fasterxml/jackson/databind/filter/TestMapFiltering.java +++ b/src/test/java/com/fasterxml/jackson/databind/filter/TestMapFiltering.java @@ -243,4 +243,31 @@ public class TestMapFiltering extends BaseMapTest .add("b", null))); assertEquals(aposToQuotes("{}"), json); } + + public void testMapViaGlobalNonEmpty() throws Exception + { + // basic Map<String,String> subclass: + ObjectMapper mapper = new ObjectMapper(); + mapper.setPropertyInclusion(JsonInclude.Value.empty() + .withContentInclusion(JsonInclude.Include.NON_EMPTY)); + assertEquals(aposToQuotes("{'a':'b'}"), mapper.writeValueAsString( + new StringMap497() + .add("x", "") + .add("a", "b") + )); + } + + public void testMapViaTypeOverride() throws Exception + { + // basic Map<String,String> subclass: + ObjectMapper mapper = new ObjectMapper(); + mapper.configOverride(Map.class) + .setInclude(JsonInclude.Value.empty() + .withContentInclusion(JsonInclude.Include.NON_EMPTY)); + assertEquals(aposToQuotes("{'a':'b'}"), mapper.writeValueAsString( + new StringMap497() + .add("foo", "") + .add("a", "b") + )); + } } |