Is there C# implementation to convert an AVRO deserialized
<GenericRecord>
back into a regular JSON format? I have successfully read the topic from Kafka and used the AvroDeserializer
but I want to convert that into a JSON format.
Here's an example: Simple JSON:
{
"value": {
"eventCreatedTimestamp": 1588694347577,
"iouDecision": "PLANE",
"iouDecisionReason": {
"value": "Optimal"
}
}
}
Same from the AVRO deserialized Generic.Record:
{Schema:
{"type":"record","name":"TheCustomerDecisionEvent",
"namespace":"com.farmxxx.tst.property.service.options.iou.messaging.avro","fields":
[{"name":"eventCreatedTimestamp","type":["null","long"]},
{"name":"iouDecision","type":["null",{"type":"enum",
"name":"TheType",
"namespace":"com.farmxxx.tst.property.service.options.iou.messaging.avro",
"symbols":["HRMR","FIELD","PLANE"]}]},
{"name":"iouDecisionReason","type":["null",{"type":"record","name":"iouDecisionReason",
"namespace":"com.farmxxx.tst.property.service.options.iou.messaging.avro",
"fields":[{"name":"value","type":["null","string"]}]}]}]}
,
contents: { eventCreatedTimestamp: 1588694347577,
iouDecision: Schema: {"type":"enum","name":"TheType",
"namespace":"com.farmxxx.tst.property.service.options.iou.messaging.avro",
"symbols":["HRMR","FIELD","PLANE"]}, value: PLANE,
iouDecisionReason: Schema: {"type":"record","name":"iouDecisionReason",
"namespace":"com.farmxxx.tst.property.service.options.iou.messaging.avro",
"fields":[{"name":"value","type":["null","string"]}]}, contents: { value: Optimal, }, }}
So the task is to get back to the Simple JSON from the AVRO Generic.Record.
The solution can be found using:
https://github.com/AdrianStrugala/AvroConvert
Avro2Json
feature.
With this you can read a topic from Kafka and translate that into simple JSON. I use that simple JSON to pass onto other clients who don't want to know about AVRO record format etc.
Many thanks to the author of the AvroConvert Github repository.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With