Support Questions

Find answers, ask questions, and share your expertise
Announcements
Now Live: Explore expert insights and technical deep dives on the new Cloudera Community BlogsRead the Announcement

converting Avro data format into Json in java

avatar
New Member

Hii,

Please can help me, By using kafkaStreaming api i get the avro data from kafka then i will try to convert avro data format into json then push into kafka,

2 REPLIES 2

avatar
Master Guru

You can use either ConvertRecord or ConvertAvroToJSON to convert your incoming Avro data to JSON. If the incoming Avro files do not have a schema embedded in them, then you will have to provide it, either to an AvroReader (for ConvertRecord) or the "Avro schema" property (for ConvertAvroToJSON).

avatar
New Member

Schema schema = ....

@SuppressWarnings("static-access") Decoder binaryDecoder = DecoderFactory.get().get().binaryDecoder(value.toString().getBytes(), null); System.out.println("test"); @SuppressWarnings("rawtypes") GenericDatumReader<GenericRecord> payloadReader = new SpecificDatumReader<GenericRecord>(schema); System.out.println("test1" + binaryDecoder.toString().length()+ "test"); GenericRecord recode = null; recode = payloadReader.read(recode, binaryDecoder); System.out.println("test2");