Avro: deserialize json - schema with optional fields

后端 未结 1 789
名媛妹妹
名媛妹妹 2021-02-14 08:37

There are a lot of questions and answers on stackoverflow on the subject, but no one that helps.

I have a schema with optional value:

{
 \"type\" : \"rec         


        
相关标签:
1条回答
  • 2021-02-14 09:42

    case 1 is working fine in java .

    {
    "username" : "2271AE67-34DE-4B43-8839-07216C5D10E1",
    "errorData" : { "string":"070226AC-9B91-47CE-85FE-15AA17972298"}
    }
    

    for case 2 Your schema is defined for union. You can update you schema as below to deserialize json.

     {
       "username" : "2271AE67-34DE-4B43-8839-07216C5D10E1",
       "errorData" : "070226AC-9B91-47CE-85FE-15AA17972298"
     }
    
    {
      "type" : "record",
      "name" : "UserSessionEvent",
      "namespace" : "events",
      "fields" : [ {
                    "name" : "username",
                    "type" : "string"
                 }, {
                    "name" : "errorData",
                    "type" :  "string" ,
                    "default" : null
                   }]
    }
    
    0 讨论(0)
提交回复
热议问题