@Test
public void testResolveUnion() throws IOException {
final SpecificDatumWriter<TestRecordWithUnion> writer = new SpecificDatumWriter<TestRecordWithUnion>();
Schema schema = TestRecordWithUnion.SCHEMA$;
ByteArrayOutputStream out = new ByteArrayOutputStream();
JsonEncoder encoder = EncoderFactory.get().jsonEncoder(schema, out);
writer.setSchema(schema);
TestRecordWithUnion c = TestRecordWithUnion.newBuilder().
setKind(Kind.BAR).setValue("rab").build();
writer.write(c, encoder);
encoder.flush();
out.close();
String expectedJson = String.format(
"{'kind':{'org.apache.avro.test.Kind':'%s'},'value':{'string':'%s'}}",
c.getKind().toString(), c.getValue()).replace('\'', '"');