AdrianStrugala / AvroConvert

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

Convert json to GenericRecord #121

Closed ssudhindrarao closed 8 months ago

ssudhindrarao commented 11 months ago

Problem statement. User will have a JSON data which is dynamic, and user doesn't have any class for that structure, Since json is also dynamic, with this user wants to send data to Kafka Producer.

Using the schema from from schema registry and whatever data has come as input, User should be able to create a Dyanamic GenericRecord on the fly. So that all the fields which are defined in the schema should get mapped with respective data which is in Input Json.

This Generic record can then be sent to producer, without having to create a Dynamic class on the fly.

If this feature already exists for C#, do let me know.

AdrianStrugala commented 11 months ago

You might want to use the JsonToAvro extension: https://github.com/AdrianStrugala/AvroConvert/blob/master/src/AvroConvert/AvroConvert.Json2Avro.cs

ssudhindrarao commented 11 months ago

Could you please elaborate a bit here. Using Json2Avro i can get the byte array, But i am looking at creating a Dynamic GenericRecord object. Is it possible?

AdrianStrugala commented 11 months ago

As I understand, you want to run the following sequence: json (deserialize and map) -> GenericRecord (send) -> KafkaProducer (serialize) -> Avro Is that correct?

If so, you can skip the two middle steps just by converting a json directly to avro. That's what AvroConvert is supporting. If you want to create an intermediate C# model (like GenericRecord) you can map it as any other class.