I'm using Jackson 2.4 to serialize objects to JSON.
When I serialize a list of objects, having some elements are null, the result JSON
string contains some "null" strings.
How do I prevent "null"
elements from being serialized? Is there any configuration for ObjectMapper
? I have already set "setSerializationInclusion(Include.NON_NULL)"
!
Here is my code :
List<String> strings = new ArrayList<>();
strings.add("string 1");
strings.add("string 2");
strings.add(null);
strings.add(null);
After serializing I got this :
[string 1, string 2, null, null]
How do I get the JSON string without "null"?
[string 1, string 2]