public static String toAvroJsonString(Object value, Schema schema) throws IOException {
try {
final ByteArrayOutputStream jsonOutputStream = new ByteArrayOutputStream();
final JsonEncoder jsonEncoder =
EncoderFactory.get().jsonEncoder(schema, jsonOutputStream);
final GenericDatumWriter writer = new GenericDatumWriter(schema);
writer.write(value, jsonEncoder);
jsonEncoder.flush();
return Bytes.toString(jsonOutputStream.toByteArray());
} catch (IOException ioe) {
throw new RuntimeException("Internal error: " + ioe);
}