-
-
Notifications
You must be signed in to change notification settings - Fork 338
Description
In moving from Jackson 2.7.6 to 2.8.3, we are now getting compiler warnings with regards to our use of the SerializationFeature.WRITE_EMPTY_JSON_ARRAYS. From what I can tell, the recommendation is to replace this with JsonInclude.Include.NON_EMPTY.
Our code previously looked like this:
public static ObjectMapper getJacksonObjectMapper() {
ObjectMapper mapper = new ObjectMapper();
mapper.configure(SerializationFeature.INDENT_OUTPUT, true);
mapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
mapper.configure(SerializationFeature.WRITE_EMPTY_JSON_ARRAYS, false);
mapper.setSerializationInclusion(JsonInclude.Include.NON_EMPTY);
return mapper;
}
and when serializing JSON, empty arrays are omitted.
If I comment out the deprecated WRITE_EMPTY_JSON_ARRAYS line, and write the exact same object, the JSON has empty array elements within it.
Here is a simple test case, just unzip and run mvn package and look at the test output and you will see something that looks like the following:
Running test.EmptyArraysTest
Printing object with WRITE_EMPTY_JSON_ARRAYS set to false:
{
"id" : "123"
}
Printing object without WRITE_EMPTY_JSON_ARRAYS:
{
"id" : "123",
"databases" : [ ]
}
What am I missing?
jackson-empty-arrays-test.zip