Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Headless deserialization to dynamic object #107

Open
alexander-miglis opened this issue May 5, 2023 · 5 comments
Open

Headless deserialization to dynamic object #107

alexander-miglis opened this issue May 5, 2023 · 5 comments
Labels
issue This doesn't seem right

Comments

@alexander-miglis
Copy link

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);

@AdrianStrugala
Copy link
Owner

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

@AdrianStrugala
Copy link
Owner

AdrianStrugala commented Jul 6, 2023

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

@alexander-miglis
Copy link
Author

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.

@AdrianStrugala
Copy link
Owner

AdrianStrugala commented Sep 18, 2023

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 AdrianStrugala added issue This doesn't seem right and removed investigation labels Dec 1, 2023
@alexander-miglis
Copy link
Author

alexander-miglis commented Dec 7, 2023

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
issue This doesn't seem right
Projects
None yet
Development

No branches or pull requests

2 participants