You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
We've recently updated xmlutil to version 0.81.0, and seem to have come across a bug in how deserialization for nullable fields is handled.
Our application accepts XML from a third party system, which we don't control. At times, rather than omit an element for missing data, it will instead provide XML with an element which is present but not real data, e.g. <Doc><Date>00.00.0000</Date></Doc> instead of <Doc></Doc>. We handle this by having a Serializer that recognises these values and outputs null instead, which is the semantically correct value.
On the previous xmlutil version we were using (0.13.0.2, so quite old), this worked fine. However, with 0.81.0, deserialization fails with the following error:
java.lang.NullPointerException: null cannot be cast to non-null type T of nl.adaptivity.xmlutil.serialization.XmlDecoderBase.TagDecoder.decodeNullableSerializableElement
at nl.adaptivity.xmlutil.serialization.XmlDecoderBase$TagDecoder.decodeNullableSerializableElement(XMLDecoder.kt:393)
From looking at the XMLDecoder code, it seems to be casting the result of the operation to T rather than T?, which may be the cause, though I'm not certain.
The quick fix is indeed casting to T? rather than to T. I've added your test GIST to the repository (using JUnit though) - thanks for that.
In addition I've made it such that encoding also works "properly". There is one error in the sample code that is significant to that. You need to have a descriptor that marks the serializer as nullable. So the code you need is:
Thank you so much for responding to this so quickly, and for the tip re: nullable for the SerialDescriptor! Looking forward to the next release so I can remove my workaround for this issue. :)
We've recently updated xmlutil to version 0.81.0, and seem to have come across a bug in how deserialization for nullable fields is handled.
Our application accepts XML from a third party system, which we don't control. At times, rather than omit an element for missing data, it will instead provide XML with an element which is present but not real data, e.g.
<Doc><Date>00.00.0000</Date></Doc>
instead of<Doc></Doc>
. We handle this by having a Serializer that recognises these values and outputs null instead, which is the semantically correct value.On the previous xmlutil version we were using (0.13.0.2, so quite old), this worked fine. However, with 0.81.0, deserialization fails with the following error:
From looking at the XMLDecoder code, it seems to be casting the result of the operation to T rather than T?, which may be the cause, though I'm not certain.
A small test which reproduces the issue is here: https://gist.github.com/conorfarrell-coats/f6a6970dd74196b3ab47a289a2dc99c9
If we're holding it wrong, very happy to be told this! Also happy to work with you to make a fix if you can give us some guidance.
The text was updated successfully, but these errors were encountered: