jackson-dataformats-binary icon indicating copy to clipboard operation
jackson-dataformats-binary copied to clipboard

[Help needed] Fix custom null serialization

Open marcospassos opened this issue 4 years ago • 6 comments

@cowtowncoder implementing a null custom serialization for an internal library, I stumbled upon a bug that prevents serialized null from being deserialized (which should affect other packages, such as JSR-353). For now, this PR only includes a test that reproduces the problem.

Error message:

com.fasterxml.jackson.databind.exc.MismatchedInputException: No content to map due to end-of-input

Could you give me some guidance on how to fix it?

marcospassos avatar Sep 26 '19 19:09 marcospassos

It'd be good to maybe file issue separately, link to/from this PR. There's one small problem with custom deserializer, not sure if it matters.

cowtowncoder avatar Sep 26 '19 21:09 cowtowncoder

It'd be good to maybe file issue separately, link to/from this PR.

I'll open a PR.

I just pushed a new commit, but it doesn't seem to fix the issue.

marcospassos avatar Sep 26 '19 21:09 marcospassos

Additional info: the same does not happen when serializing/deserializing to/from JSON.

marcospassos avatar Sep 26 '19 21:09 marcospassos

Ok. Thank you for verifying.

I think this could be related to one oddity wrt Avro handling of nulls: unless null value is part of union, it "does not exist": that is, it does not take any space. Value of a field with only null type is always null, and nothing is encoded. This is fine in theory, but presents unique problem at root-level reader: it is not easy to know if stream has ended or not -- just because there are no bytes left does not necessarily mean we are done as null may still be implicitly available! (I had to fix one bug earlier related to this).

cowtowncoder avatar Sep 27 '19 21:09 cowtowncoder

Dammit, now I see why I couldn't find an easy way to fix it myself without consuming your limited time. But it seems a critical bug to fix, as it can break things seriously. Again, let me know if I can help you fix it.

marcospassos avatar Sep 28 '19 13:09 marcospassos

@marcospassos Unfortunately I do not really have time to work on this now.

cowtowncoder avatar Sep 29 '19 00:09 cowtowncoder