org.apache.kafka.common.errors.SerializationException: Error serializing Avro message
java.lang.ClassCastException: org.json.simple.JSONObject cannot be cast to org.apache.avro.generic.IndexedRecord
Here is my code -
private KafkaProducer<String, GenericRecord> kafkaProducer;
Schema.Parser parser = new Schema.Parser();
Schema schema = parser.parse(value.getSchema());
GenericRecord avroRecord = new GenericData.Record(schema);
avroRecord.put("ci", value.getCi());
avroRecord.put("cn", value.getCn());
avroRecord.put("n", value.getN());
avroRecord.put("tg", value.getTg());
avroRecord.put("ts", value.getTs());
avroRecord.put("pl", value.getPl());
//In "value", value.getPl() is of type "T" but from where I am setting it, it's type is org.json.simple.JSONObject
ProducerRecord<String, GenericRecord> record = new ProducerRecord<String, GenericRecord>("test", avroRecord);
try {
kafkaProducer.send(record);
} catch (SerializationException e) {
// may need to do something with it
}
Please find the attached schema.
--
You received this message because you are subscribed to the Google Groups "Confluent Platform" group.
To unsubscribe from this group and stop receiving emails from it, send an email to confluent-platform+unsub...@googlegroups.com.
To post to this group, send email to confluent-platform@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/confluent-platform/e2c20eba-47b6-482c-a63d-ebbcc7c764c1%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
To post to this group, send email to confluent...@googlegroups.com.
{"type":"record","name":"hotelcrimes","namespace":"com.oyo","fields":[{"name":"_id","type":{"type":"record","name":"id","fields":[{"name":"oid","type":["null","string"]}]}},{"name":"bid","type":["null","int"]},{"name":"biv","type":["null","string"]},{"name":"cca","type":["null","string"]},{"name":"ct","type":["null","string"]},{"name":"hid","type":["null","int"]},{"name":"md","type":{"type":"record","name":"md","fields":[{"name":"feedback_id","type":["null","int"]},{"name":"remove_comment","type":["null","string"]},{"name":"shifting_id","type":["null","int"]},{"name":"ticket_id","type":["null","int"]}]}},{"name":"noc","type":["null","double"]},{"name":"oyo_id","type":["null","string"]},{"name":"r","type":["null","boolean"]},{"name":"st","type":["null","boolean"]},{"name":"ufc","type":["null","boolean"]},{"name":"updated_at","type":["null","string"]},{"name":"created_at","type":["null","string"]}]}