I am using Avro 1.8.2 and I am trying to convert JSON into a GenericRecord
DatumReader<GenericData.Record> datumReader = new GenericDatumReader<>(schema);
Decoder decoder = DecoderFactory.get().jsonDecoder(schema, jsonStr);
datumReader.read(null, decoder)
I get JSON data from a third party and I have no control over the elements. The AVRO schema is
{
"namespace":"com.avro.generated",
"type":"record",
"name":"TestEvent",
"fields":[
{"name":"userId","type":"string"},
{"name":"frm","type":"string"},
{"name":"issuerName","type":"string"},
{"name":"profileId","type":"string"}
]
}
If I use this JSON
{
"userId":"5435tert34tgcb21391f7bda71",
"frm":"somerm",
"issuerName":"somenameorts",
"profileId":"0werwerwer0000-0000-000000000000"
}
It works fine. However if the json does not contain the frm element as shown below
{
"userId":"5435tert34tgcb21391f7bda71",
"issuerName":"somenameorts",
"profileId":"0werwerwer0000-0000-000000000000"
}
Then I get this exception
org.apache.avro.AvroTypeException: Expected field name not found: frm.
Is there any way to make this work?. I have no control over the JSON. I have read other SO posts about using schemas like
{"name":"frm","type":["null","string"],"default": "null"}
But none of this is working
Thanks