I am working with a the following schema.
{"fields":[{"default":null,"name":"corelationId","type":["null","string"]},{"default":null,"name":"eventId","type":["null","string"]},{"default":null,"name":"eventTime","type":["null","string"]},{"default":null,"name":"eventType","type":["null","string"]},{"default":null,"name":"resourceOrders","aliases":["resourceOrder"],"type":["null",{"fields":[{"default":null,"name":"expectedCompletionDate","type":["null","string"]},{"default":null,"name":"resourceOrderItem","type":["null",{"items":{"fields":[{"default":null,"name":"errorMessage","type":["null",{"items":{"fields":[{"default":null,"name":"additionalInfoCode","type":["null","string"]},{"default":null,"name":"additionalInfoCorrectionValue","type":["null","string"]},{"default":null,"name":"additionalInfoMessage","type":["null","string"]},{"default":null,"name":"code","type":["null","string"]},{"default":null,"name":"message","type":["null","string"]}],"name":"item","aliases":["items"],"namespace":"properties.resourceOrders.properties.resourceOrderItem.items.properties.errorMessage","type":"record"},"type":"array"}]}],"name":"item","aliases":["items"],"namespace":"properties.resourceOrders.properties.resourceOrderItem","type":"record"},"type":"array"}]}],"name":"resourceOrders","aliases":["resourceOrder"],"namespace":"properties","type":"record"}]},{"default":null,"name":"sourceSystem","type":["null","string"]}],"name":"NotifyExportResponseAvro","namespace":"xxx.yyy.zzz","type":"record"}
I am trying to validate following payload
{"corelationId":{"string":"cxd-abc"},"eventId":{"string":"1231250602"},"eventTime":{"string":"2022-09-27 09:18:24.495"},"eventType":{"string":"ResourceOrderExportResponseEvent"},"resourceOrder":{"properties.resourceOrder":{"expectedCompletionDate":{"string":"2022-10-12"},"resourceOrderItem":null}},"sourceSystem":{"string":"zzz"}}
The command I am using
java -jar ~/.m2/repository/org/apache/avro/avro-tools/1.11.2/avro-tools-1.11.2.jar fromjson --schema-file some.avsc data-basic.json
However I am getting the following error:
Exception in thread "main" org.apache.avro.AvroTypeException: Unknown union branch properties.resourceOrder at org.apache.avro.io.JsonDecoder.readIndex(JsonDecoder.java:434) at org.apache.avro.io.ResolvingDecoder.readIndex(ResolvingDecoder.java:282) at org.apache.avro.generic.GenericDatumReader.readWithoutConversion(GenericDatumReader.java:188) at org.apache.avro.generic.GenericDatumReader.read(GenericDatumReader.java:161) at org.apache.avro.generic.GenericDatumReader.readField(GenericDatumReader.java:260) at org.apache.avro.generic.GenericDatumReader.readRecord(GenericDatumReader.java:248) at org.apache.avro.generic.GenericDatumReader.readWithoutConversion(GenericDatumReader.java:180) at org.apache.avro.generic.GenericDatumReader.read(GenericDatumReader.java:161) at org.apache.avro.generic.GenericDatumReader.read(GenericDatumReader.java:154) at org.apache.avro.tool.DataFileWriteTool.run(DataFileWriteTool.java:89) at org.apache.avro.tool.Main.run(Main.java:67) at org.apache.avro.tool.Main.main(Main.java:56)
However when I change the data to the following the payload is getting validated.. Though I've used resourceOrder as an aliases
...
"resourceOrder": {
"properties.resourceOrders": {
"expectedCompletionDate": {
"string": "2022-10-12"
},
"resourceOrderItem": null
}
},
...
Question is why avro-tool is accepting aliases inside an union? Is this bug in the tool or this valid behavior?
How can I change the schema as I can get both resourceOrder and resourceOrders?