It is possible to do it with a custom JsonDecoder. I wrote one that does this at: https://github.com/zolyfarkas/avro/blob/trunk/lang/java/avro/src/main/java/org/apache/avro/io/ExtendedJsonDecoder.java <https://github.com/zolyfarkas/avro/blob/trunk/lang/java/avro/src/main/java/org/apache/avro/io/ExtendedJsonDecoder.java>
hope it helps. —Z > On Apr 13, 2019, at 9:24 AM, Martin Mucha <[email protected]> wrote: > > Hi, > > is it possible by design to deserialize JSON with schema having optional > value? > Schema: > > { > "type" : "record", > "name" : "UserSessionEvent", > "namespace" : "events", > "fields" : [ { > "name" : "username", > "type" : "string" > }, { > "name" : "errorData", > "type" : [ "null", "string" ], > "default" : null > }] > } > Value to deserialize: > {"username" : "2271AE67-34DE-4B43-8839-07216C5D10E1"} > I also tried to change order of type, but that changed nothing. I know I can > produce ill-formated JSON which could be deserialized, but that's not > acceptable. AFAIK given JSON with required `username` and optional > `errorData` cannot be deserialized by design. Am I right? > > thanks.
