0

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.

Kulasangar
  • 9,046
  • 5
  • 51
  • 82
  • Does this answer your question? [How to fix Expected start-union. Got VALUE\_NUMBER\_INT when converting JSON to Avro on the command line?](https://stackoverflow.com/questions/27485580/how-to-fix-expected-start-union-got-value-number-int-when-converting-json-to-av) – tgdavies Aug 03 '23 at 09:26

0 Answers0