From 747f0007de0d335314ac0f2407fd8727d4f83d81 Mon Sep 17 00:00:00 2001 From: Tatu Saloranta Date: Wed, 17 Aug 2016 22:22:15 -0700 Subject: [PATCH] improve #1327 test --- .../databind/SerializationFeature.java | 2 +- .../jackson/failing/JsonInclude1327Test.java | 23 +++++++++++++++---- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/fasterxml/jackson/databind/SerializationFeature.java b/src/main/java/com/fasterxml/jackson/databind/SerializationFeature.java index e48b12e9b6..e8d1cb3160 100644 --- a/src/main/java/com/fasterxml/jackson/databind/SerializationFeature.java +++ b/src/main/java/com/fasterxml/jackson/databind/SerializationFeature.java @@ -295,7 +295,7 @@ public enum SerializationFeature implements ConfigFeature * Feature is enabled by default. * * @deprecated Since 2.8 there are better mechanism for specifying filtering; specifically - * using {@link com.fasterxml.jackson.annotation.JsonFormat} or configuration overrides. + * using {@link com.fasterxml.jackson.annotation.JsonInclude} or configuration overrides. */ @Deprecated // since 2.8 WRITE_EMPTY_JSON_ARRAYS(true), diff --git a/src/test/java/com/fasterxml/jackson/failing/JsonInclude1327Test.java b/src/test/java/com/fasterxml/jackson/failing/JsonInclude1327Test.java index e75a80619a..40fbeea91c 100644 --- a/src/test/java/com/fasterxml/jackson/failing/JsonInclude1327Test.java +++ b/src/test/java/com/fasterxml/jackson/failing/JsonInclude1327Test.java @@ -16,11 +16,16 @@ public class JsonInclude1327Test extends BaseMapTest { @JsonInclude(JsonInclude.Include.NON_EMPTY) - public static class Issues1327Bean { + static class Issue1327BeanEmpty { public String myString = "stuff"; public List myList = new ArrayList(); } + static class Issue1327BeanAlways { + @JsonInclude(JsonInclude.Include.ALWAYS) + public List strings = new ArrayList(); + } + /* /********************************************************** /* Unit tests @@ -28,15 +33,25 @@ public static class Issues1327Bean { */ // for [databind#1327] - public void testIssue1327() throws Exception { + public void testClassDefaultsForEmpty() throws Exception { ObjectMapper om = new ObjectMapper(); om.setSerializationInclusion(JsonInclude.Include.NON_NULL); - final Issues1327Bean input = new Issues1327Bean(); - final String jsonString = om.writeValueAsString(input); + final String jsonString = om.writeValueAsString(new Issue1327BeanEmpty()); if (jsonString.contains("myList")) { fail("Should not contain `myList`: "+jsonString); } } + + public void testClassDefaultsForAlways() throws Exception { + ObjectMapper om = new ObjectMapper(); + om.setSerializationInclusion(JsonInclude.Include.NON_EMPTY); + + final String jsonString = om.writeValueAsString(new Issue1327BeanAlways()); + + if (!jsonString.contains("myList")) { + fail("Should contain `myList` with Include.ALWAYS: "+jsonString); + } + } }