FasterXML / jackson-dataformats-binary

Uber-project for standard Jackson binary format backends: avro, cbor, ion, protobuf, smile
Apache License 2.0
310 stars 133 forks source link

[avro] Deserialize from newer version to older one throws NullPointerException #161

Closed lukidzi closed 5 years ago

lukidzi commented 5 years ago

Version 2.9.0 and 2.9.8

Test to reproduce 07da0ea27aafa2598066298af2adc70bf7fd1042

I have event in newer version of schema and I want to deserialize it with older version. Newer schema has additional field which might be null. During deserialization there is NullPointerException :

java.lang.NullPointerException
    at com.fasterxml.jackson.dataformat.avro.deser.UnionReader._decodeIndex(UnionReader.java:63)
    at com.fasterxml.jackson.dataformat.avro.deser.UnionReader.skipValue(UnionReader.java:45)
    at com.fasterxml.jackson.dataformat.avro.deser.AvroFieldReader$Structured.skipValue(AvroFieldReader.java:61)
    at com.fasterxml.jackson.dataformat.avro.deser.RecordReader$Resolving.nextFieldName(RecordReader.java:222)
    at com.fasterxml.jackson.dataformat.avro.deser.AvroParserImpl.nextFieldName(AvroParserImpl.java:110)
    at com.fasterxml.jackson.databind.deser.BeanDeserializer.vanillaDeserialize(BeanDeserializer.java:294)
    at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserialize(BeanDeserializer.java:151)
    at com.fasterxml.jackson.databind.ObjectReader._bindAndClose(ObjectReader.java:1608)
    at com.fasterxml.jackson.databind.ObjectReader.readValue(ObjectReader.java:1185)
    at com.fasterxml.jackson.dataformat.avro.schemaev.ErrorReproduceTest.testShouldDeserialize(ErrorReproduceTest.java:72)

NullPointer occures when new field has UnionType null and one of(Record, Map, Array).

Newer schema which has additional field:

{
  "type": "record",
  "name": "V1",
  "namespace": "test",
  "doc": "simple schema version 2 testing compatibility",
  "fields": [
    {
      "name": "name",
      "type": "string",
      "doc": "object name"
    },
    {
      "name": "label",
      "type": 
      [
        "null",
        {
          "type" : "array",
          "items" : "string"
        }
      ],
      "doc": "object label"
    }
  ]
}

Older Schema:

{
  "type": "record",
  "name": "V1",
  "namespace": "test",
  "doc": "simple schema testing compatibility",
  "fields": [
    {
      "name": "name",
      "type": "string",
      "doc": "object name"
    }
  ]
}

I serialize event with newer schema and later I want to deserialize with older schema

{
"name" : "test",
"label": null
}

Do you have any idea how can I configure mapper to avoid this problem or it has to be fixed?

cowtowncoder commented 5 years ago

Hoping to merge the fix, as soon as we get CLA. Might make it in 2.9.9; if not, 2.10.0.