AdrianStrugala / AvroConvert

Rapid Avro serializer for C# .NET
Other
96 stars 27 forks source link

Does this library implement the Json Encoding spec? #156

Open ridomin opened 2 months ago

ridomin commented 2 months ago

Convert Avro to Json does not follow the Avro Json Encoding spec

When using union types to define optional parameters, by adding null to the type union, the produced Json does not follow the spec

https://avro.apache.org/docs/1.11.1/specification/#json-encoding

When using a record field with a type like

"name" : "MyField"
"type": [ "null", "string" ],

And converting the avro bytes to Json

The expected output should be

{
  "MyField" : { "string" : "MyValue" } 
}

instead I got

{
  "MyField" : "MyValue"
}
AdrianStrugala commented 2 months ago

Hey @ridomin,

That's right, the output JSON is compatible with .NET model, not with Avro Json spec. Could you provide more details on your use case?

Best, Adrian

ridomin commented 2 months ago

Avro has very specific rules to declare which fields are required vs. optional, using union with null, and those rules are different from the .NET serialization model.

My use case is to validate the messages based on Avro schemas, including which fields are required. Without it I cannot apply the Avro schema to validate.

AdrianStrugala commented 2 months ago

Would that be helpful if there were an API exposing the schema model?

ridomin commented 2 months ago

If that schema captures which fields are optional, yes it will be helpful.