You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@johnzon.apache.org by "Mark Struberg (JIRA)" <ji...@apache.org> on 2018/02/26 12:46:00 UTC
[jira] [Resolved] (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:all-tabpanel ]
Mark Struberg resolved JOHNZON-151.
-----------------------------------
Resolution: Fixed
Fix Version/s: 1.1.7
Seems this already got released with 1.1.6 even.
Verified for 1.1.7 at lest.
txs for the report and fix!
> 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
> Assignee: Mark Struberg
> Priority: Major
> Fix For: 1.1.7
>
> 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
(v7.6.3#76005)