You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@johnzon.apache.org by "Romain Manni-Bucau (JIRA)" <ji...@apache.org> on 2017/12/29 09:16:00 UTC
[jira] [Commented] (JOHNZON-151) Serializing nulls within a list,
within a type or map produces unexpected results
[ https://issues.apache.org/jira/browse/JOHNZON-151?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16306136#comment-16306136 ]
Romain Manni-Bucau commented on JOHNZON-151:
--------------------------------------------
Hi Steven,
very good catch! Do you want to submit a PR to fix it?
Quick tip: we have a flag to serialize or not nulls in the config this should respect I think.
> Serializing nulls within a list, within a type or map produces unexpected results
> ---------------------------------------------------------------------------------
>
> Key: JOHNZON-151
> URL: https://issues.apache.org/jira/browse/JOHNZON-151
> Project: Johnzon
> Issue Type: Bug
> Components: Mapper
> Affects Versions: 1.1.0, 1.1.1, 1.1.2, 1.1.3, 1.1.4, 1.1.5
> Reporter: Steven Walters
> Attachments: johnzon-mapper-nulls-in-collection.zip
>
>
> 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
> {code:title=MappingGeneratorImpl.java}
> private void writeValue(final Class<?> type, ...
> ...
> if (objectConverterToUse == null) {
> objectConverterToUse = config.findObjectConverterWriter(o.getClass());
> }
> {code}
> 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
> {code:title=MappingGeneratorImpl.java}
> private void writeItem(final Object o, final Collection<String> ignoredProperties, JsonPointerTracker jsonPointer) {
> if (!writePrimitives(o)) {
> if (Collection.class.isInstance(o)) {
> {code}
> {code:title=MappingGeneratorImpl.java}
> private boolean writePrimitives(final Object value) {
> boolean handled = false;
> if (value == null) {
> return true; // fake a write
> }
> {code}
> 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.
--
This message was sent by Atlassian JIRA
(v6.4.14#64029)