I'm currently trying to convert a JsonObject into an Avro Generic Record where I stumbled upon this issue.
My schema toString() looks like:
{
"type":"record",
"name":"list",
"namespace":"list15",
"fields":[
{
"name":"element",
"type":{
"type":"record",
"name":"element",
"namespace":"element8",
"fields":[
{
"name":"name",
"type":[
"null",
"string"
],
"default":null
},
{
"name":"value",
"type":{
"type":"array",
"items":{
"type":"record",
"name":"list",
"namespace":"list16",
"fields":[
{
"name":"element",
"type":"string"
}
]
}
}
}
]
}
}
]
}
and my JsonObject toString() looks like:
{"element":{"name":"customer_id","value":[]}}
This is how I'm trying to do the conversion:
val schemaStr = attribute.schema.toString() // here attribute is a GenericRecord type
val genericRecordStr = jsonRootObject.toString()
val schemaParser = Schema.Parser()
val schema = schemaParser.parse(schemaStr)
val decoderFactory = DecoderFactory()
val decoder = decoderFactory.jsonDecoder(schema, genericRecordStr)
val reader = GenericDatumReader<GenericData.Record>(schema)
val genericRecord = reader.read(null, decoder)
As you can see the JsonObject.toString() output, it obliges to the Schema. Not sure why the conversion is complaining and where I'm going wrong?
Any help could be appreciated.