Commit e15f7cb
committed
[Java] Fix default values of fields with UNION schemas where the NULL schema comes first
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:
```
{
"name": "exampleDateTime",
"type": ["null", { "type": "long", "logicalType": "local-timestamp-millis" }],
"default": 1746088255000
}
```
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):
```
record SomeRecord {
union{array<int?>, null} optArrayOptItemVal = [4];
}
```
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:
```
"type": ["null", { "type": "int" }]
```
which also fails the non-NULL schema first assumption.1 parent 999b36f commit e15f7cb
File tree
2 files changed
+18
-1
lines changed- lang/java/avro/src
- main/java/org/apache/avro/util/internal
- test/java/org/apache/avro/util/internal
2 files changed
+18
-1
lines changedLines changed: 5 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
115 | 115 | | |
116 | 116 | | |
117 | 117 | | |
118 | | - | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
119 | 123 | | |
120 | 124 | | |
121 | 125 | | |
| |||
Lines changed: 13 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
79 | 79 | | |
80 | 80 | | |
81 | 81 | | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
82 | 86 | | |
83 | 87 | | |
84 | 88 | | |
| |||
90 | 94 | | |
91 | 95 | | |
92 | 96 | | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
93 | 106 | | |
94 | 107 | | |
95 | 108 | | |
| |||
0 commit comments