AvroUtils { public static byte[] encodeAvroIndexedRecordAsJson(Schema schema, IndexedRecord record) throws IOException { ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); JsonEncoder encoder = EncoderFactory.get().jsonEncoder(schema, outputStream); return encodeAvroIndexedRecord(schema, record, outputStream, encoder); }  static byte[] encodeAvroSpecificRecord(Class<T> clazz, T record); static byte[] encodeAvroIndexedRecord(Schema schema, IndexedRecord record); static byte[] encodeAvroIndexedRecordAsJson(Schema schema, IndexedRecord record); static T decodeAvroSpecificRecord(Class<T> clazz, byte[] bytes); static T decodeAvroSpecificRecord(Class<T> clazz, byte[] bytes, T reuse); static T decodeAvroSpecificRecord(Schema schema, byte[] bytes, T reuse); static T decodeAvroGenericRecord(Schema schema, byte[] bytes, T reuse); static GenericRecord decodeAvroGenericRecord(Schema schema, byte[] bytes); static T decodeJsonAsAvroGenericRecord(Schema schema, byte[] bytes, T reuse);  }
@Test public void testEncodeAvroIndexedRecordAsJson() throws Exception { String expectedValue = "name123"; Schema schema = Schema.parse(SCHEMA_STRING); GenericRecord record = new GenericData.Record(schema); record.put("first", expectedValue); String json = new String(encodeAvroIndexedRecordAsJson(schema, record)); Assert.assertTrue(json.contains(expectedValue)); }