AvroConvert icon indicating copy to clipboard operation
AvroConvert copied to clipboard

Headless deserialization to dynamic object

Open alexander-miglis opened this issue 2 years ago • 5 comments

would it be possible to create a feature to dynamically generate an object based on the schema

Something like this dynamic obj = AvroConvert.DeserializeHeadless<ExpandoObject>(dataBytes, schemaStr);

alexander-miglis avatar May 05 '23 10:05 alexander-miglis

Hello, Thank you for your idea. I will investigate the solution and come back to you. Regards, Adrian

AdrianStrugala avatar May 08 '23 11:05 AdrianStrugala

Hello @alexander-miglis,

Sorry for the late answer. I am not sure if I get your question correctly, but the statement you have put is absolutely correct at the moment. As soon as ExpandoObject is supported #112 it will result with a dynamic object.

Regards, Adrian

AdrianStrugala avatar Jul 06 '23 11:07 AdrianStrugala

I saw you added this feature and I appreciate that you consider doing it. It would really help me to dynamically read objects from Kafka and re-serialize them as json for example.

alexander-miglis avatar Jul 24 '23 14:07 alexander-miglis

Hello @alexander-miglis

The new feature is ready. It's available from v 3.4.0 I've found another way of doing so. It's simply:

dynamic deserializedObject = AvroConvert.Deserialize<dynamic>(byte[] avroObject);

Please let me know if it solves your case. For Avro to Json conversion, you can simply use AvroConvert.Avro2Json extension.

Best, Adrian

Edit: Uh, it does not work with headless Avro files yet

AdrianStrugala avatar Sep 18 '23 14:09 AdrianStrugala

In my use case I get the schema from a schema registry and then read out the message from Kafka headless. So unfortunately this solution does not work for me yet... I would require the headless version of this feature.

The idea is that I would be able to use the dynamic object to serialize it to other formats, like json, without having to implement a full object that matches the schema.

alexander-miglis avatar Dec 07 '23 15:12 alexander-miglis