confluent-kafka-dotnet icon indicating copy to clipboard operation
confluent-kafka-dotnet copied to clipboard

How can we convert reflected type instead of concrete type and convert to json

Open bhatrohit85 opened this issue 4 years ago • 2 comments

Description

I have scenario where i will dynamically create class using reflection using schema json and then want to consume from a kafka topic expecting that reflected class. If i use ISpecificRecord in consumer builder and avrodeserializer , it throws error in consume method i.e value deserialization error . If i use genericrecord t consume , i do not know how to convert that to json.

Please help me how can i send reflected type in consumer , else how can i use genericrecord to convert to JSON.

How to reproduce

Please find the consumer code and screenshots to re-produce the issue.

github-avroconvert.zip

Checklist

Please provide the following information:

  • [ ] A complete (i.e. we can run it), minimal program demonstrating the problem. No need to supply a project file.
  • [ ] Confluent.Kafka nuget version.- 1.5.3
  • [ ] Apache Kafka version. 1.5.3
  • [ ] Client configuration.
  • [ ] Operating system.Windows 10
  • [ ] Provide logs (with "debug" : "..." as necessary in configuration).
  • [ ] Provide broker log excerpts.
  • [ ] Critical issue.

bhatrohit85 avatar Feb 22 '21 15:02 bhatrohit85

i'm a bit confused as to what you are doing. note that the avro specific serdes can only be used with classes generated using avrogen. generic records must be used on avro serialized data but "i will dynamically create class using reflection using schema json" sounds like you aren't doing that?

mhowlett avatar Mar 09 '21 21:03 mhowlett

@mhowlett This issue also occurs when the classes are generated via avrogen.

I think the actual issue is that using AvroDeserializer<ISpecificRecord> does not work although the Apache.Avro library would support it.

If you try to use AvroDeserializer<ISpecificRecord> the following line will throw as the ISpecificRecord interface does not contain a _SCHEMA field: https://github.com/confluentinc/confluent-kafka-dotnet/blob/376a3250c06f347c6492e90b9921f55eec7a5676/src/Confluent.SchemaRegistry.Serdes.Avro/SpecificDeserializerImpl.cs#L56

PSanetra avatar Dec 20 '22 19:12 PSanetra