tarantool/avro-schema

No support for optional fields

misiek08 opened this issue · 2 comments

Schema:

{
        "type": "record",
        "name": "User",
        "fields": [
            {"name": "username", "type": "string"},
            {"name": "phone", "type": "long"},
            {"name": "age", "type": ["int", "null"]}
        ]
}

and given data:

{
 "username": "tester",
 "phone": 123456789,
 "age": 123
}

returns on validator:

[
  "age: Expecting NIL or MAP, encountered LONG"
]

It should parse correctly, because Avro schema is correct.

The schema defines age field as a union. According to avro Json serialisation rules a union value is encoded as either null, or {'type':value}.

I.e. the validator is acting according to the specification.

As @mejedi said that is an expected behavior.

By now that issue can be resolved by using the nullability flag (* at the end f type name).