Details
Description
When a Collection (such as a List) contains a null entry and is serialized through a parent map or defined type, the serialization produces unexpected results.
With 1.1.0 through 1.1.4, the nulls are silently ignored.
With 1.1.5, a NullPointerException occurs instead.
I did not check 1.0.0
Local analysis indicates that in 1.1.5, code block
private void writeValue(final Class<?> type, ... ... if (objectConverterToUse == null) { objectConverterToUse = config.findObjectConverterWriter(o.getClass()); }
is the culprit by trying to invoke getClass() on a null object.
Nulls are ignored in 1.1.4 and prior due to code blocks
private void writeItem(final Object o, final Collection<String> ignoredProperties, JsonPointerTracker jsonPointer) { if (!writePrimitives(o)) { if (Collection.class.isInstance(o)) {
private boolean writePrimitives(final Object value) { boolean handled = false; if (value == null) { return true; // fake a write }
That is, the writeItem invokes writePrimitives and writePrimitives says it handled the null, when it in fact did nothing.
Currently serializing null within a list only produces correct results when the list is the root object of serialization.
Test cases attached; run mvn test to see include tests against 1.1.5
I've had to include our own altered copy of MappingGeneratorImpl to the classpath (at a higher priority) to workaround the issue indicated here in our project.