Skip to content

Commit

Permalink
improve #1327 test
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Aug 18, 2016
1 parent dd55294 commit 747f000
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,27 +16,42 @@ public class JsonInclude1327Test
extends BaseMapTest
{
@JsonInclude(JsonInclude.Include.NON_EMPTY)
public static class Issues1327Bean {
static class Issue1327BeanEmpty {
public String myString = "stuff";
public List<String> myList = new ArrayList<String>();
}

static class Issue1327BeanAlways {
@JsonInclude(JsonInclude.Include.ALWAYS)
public List<String> strings = new ArrayList<String>();
}

/*
/**********************************************************
/* Unit tests
/**********************************************************
*/

// 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);
}
}
}

0 comments on commit 747f000

Please sign in to comment.