Maciej Noszczyński created AVRO-4235:
----------------------------------------

             Summary: JacksonUtils' toObject incorrectly assumes, that a 
non-NULL schema always comes first
                 Key: AVRO-4235
                 URL: https://issues.apache.org/jira/browse/AVRO-4235
             Project: Apache Avro
          Issue Type: Bug
          Components: java
            Reporter: Maciej Noszczyński


The assumption in `JacksonUtils#toObject(JsonNode, Schema)`, that the actual 
data schema in a UNION schema (of some data with NULL), always comes first, is 
incorrect.

For example, a field with this schema will have its default value converted 
incorrectly:
{code:json}
  "name": "exampleDateTime",
  "type": ["null", \{ "type": "long", "logicalType": "local-timestamp-millis" 
}],
  "default": 1746088255000
{code}
Here the "null" schema explicitly comes first and the assumption is no longer 
correct (JacksonUtils tries to interpret the value 1746088255000 using the NULL 
schema).

Another example using Avro IDL (nullable field, containing an array of nullable 
items):
{code:java}
record SomeRecord {
  union{array<int?>, null} optArrayOptItemVal = [4];
}
{code}
In this case, the "optArrayOptItemVal" field fulfills the assumption, but the 
array item's schema does not. On my machine, with Avro 1.12.1, the item's 
schema is the following:
{code:json}
 {"type": ["null", { "type": "int" }]}
{code}
which also fails the non-NULL schema first assumption.

All of the above examples are successfully parsed or converted through the Avro 
IDL library to a Schema object.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to