@SuppressWarnings({ "rawtypes", "unchecked" })
public static String toAvroJsonString(IndexedRecord record) throws IOException {
final Schema schema = record.getSchema();
try {
final ByteArrayOutputStream jsonOutputStream = new ByteArrayOutputStream();
final JsonEncoder jsonEncoder =
EncoderFactory.get().jsonEncoder(schema, jsonOutputStream);
final SpecificDatumWriter writer = new SpecificDatumWriter(record.getClass());
writer.write(record, jsonEncoder);
jsonEncoder.flush();
return Bytes.toString(jsonOutputStream.toByteArray());
} catch (IOException ioe) {
throw new RuntimeException("Internal error: " + ioe);
}