I'm using this Avro schema:
prices-state.avsc
{
"namespace": "com.company.model",
"name": "Product",
"type": "record",
"fields": [
{
"name": "product_id",
"type": "string"
},
{
"name": "sale_prices",
"type": {
"name": "sale_prices",
"type": "record",
"fields": [
{
"name": "default",
"type": {
"name": "default",
"type": "record",
"fields": [
{
"name": "order_by_item_price_by_item",
"type": [
"null",
{
"name": "markup_strategy",
"type": "record",
"fields": [
{
"name": "type",
"type": {
"name": "type",
"type": "enum",
"symbols": ["margin", "sale_price"]
}
}
]
}
]
},
{"name": "order_by_item_price_by_weight", "type": ["null", "string"]},
{"name": "order_by_weight_price_by_weight", "type": ["null", "string"]}
]
}
}
]
}
}
]
}
It validates properly on this website so I'm assuming the schema is valid.
I'm having issues building a JSON file that should then be encoded using the above schema.
I'm using this JSON for some testing:
test.json
{
"product_id": "123",
"sale_prices": {
"default": {
"order_by_item_price_by_item": {
"markup_strategy": {
"type": {"enum": "margin"}
}
},
"order_by_item_price_by_weight": null,
"order_by_weight_price_by_weight": null
}
}
}
When running java -jar avro-tools-1.8.2.jar fromjson --schema-file prices-state.avsc test.json
I get:
Exception in thread "main" org.apache.avro.AvroTypeException: Unknown union branch markup_strategy
I read here that I have to wrap things inside unions because of JSON Encoding so I tried different combinations but no one seemed to work.