Open msempere opened 1 month ago
I have the same requirement. I found that using map[string]interface{} will break an assumption of the library. ie. It only supports struct. Reasons:
It would be nice if this library can support map[string]interface{}, even at the expense of losing some of the features.
Description
I'm currently working on a project where I need to serialize and send messages to Confluent Kafka using the Confluent Schema Registry and AVRO. The challenge I'm facing is that the messages have an unknown structure, and I only have the schema ID and topic.
I've tried using
interface{}
andmap[string]interface{}
butser.Serialize(topic, &record)
fails and I'm unable to serialize the message. One of the errors I'm getting isunknown type interface
.Detailed Scenario
I have a log file with JSON records that contain the schema ID, topic, and a JSON message to be sent to Confluent Kafka. The JSON message is arbitrary, and I don't know its structure in advance. Here's the structure when reading the records:
The Issue
I'm unable to serialize the
Msg
without knowing its structure. Here is the code I'm using:This throws an
unknown type interface
error when usingMsg map[string]interface{}
orinterface{}
.Alternative Attempt
As an alternative, I tried using
github.com/hamba/avro/v2
to serialize theMsg
with the schema retrieved fromschemaRegistryClient.GetBySubjectAndID
, but it didn't work either:This throws a
float64 is unsupported for Avro int
error for Msg with just anint
value.Question
How can I accomplish serializing an arbitrary JSON message using AVRO and the schema registry? Any help or guidance would be greatly appreciated.
Thanks!
How to reproduce
See code above. I'm happy to share the full code if needed.
Checklist
Please provide the following information:
LibraryVersion()
):2.5.0
ConfigMap{...}
"debug": ".."
as necessary)