Home > Mobile >  Unable to create a kafka message to producer - Expected start-union. Got VALUE_STRING error
Unable to create a kafka message to producer - Expected start-union. Got VALUE_STRING error

Time:11-04

i have a avsc file


{
  "namespace": "uk.asda.audit",
  "type": "record",
  "name": "loyalty_data",
  "fields": [
    {"name": "customerId",  "type": "string"},
    {"name": "customerNumber", "type": ["null", "string"], "default": null},
    {"name": "loyalitynumber", "type": ["null", "string"], "default": null},
    {"name": "correlationId",  "type": "string"},
    {"name": "timestamp",  "type": "string"},
        {"name": "sku",  "type": "enum", "symbols": ["NO","YES"]}]},
        {"name": "loyalitycodes",  "type": "array", "items":{ "name":"loyalitycode", "type":"string", } }
  ]
}

when i was trying to create a sample data in json format based on the above avsc for kafka consumer i am getting the below error upn testing

{
  "customerId": "ahdzeha46",
  "customerNumber": "473363621",
  "loyalitynumber": "45354456456",
  "correlationId": "corr-473363621",
  "timestamp": "2021-08-09T12:20:15",
  "sku": "NO",
  "entitlementCodes": [
  {
    "loyalitycodes": "A238472ASD"
  }
 ]
}

Caused by: org.apache.avro.AvroTypeException: Expected start-union. Got VALUE_STRING

how to rectify and create the sample data for testing ?

i have tried creating the sample json data based on the avsc schema and also prepared the json data as per the avsc schema however i am getting the above error

CodePudding user response:

The JSON representation for union needs to specify the type

{
  "customerId": "ahdzeha46",
  "customerNumber": {
     "string": "473363621"
  },
  "loyalitynumber": {
     "string": "45354456456"
  },
  "correlationId": "corr-473363621",
  "timestamp": "2021-08-09T12:20:15",
  "sku": "NO",
  "entitlementCodes": [
     {
        "loyalitycodes": "A238472ASD"
     }
  ]
}

I'm not sure about entitlementCodes. You need to fix the rest of JSON as well.

  • Related