Schema schm = reflectData.getSchema(AnotherSampleRecord.class);
ReflectDatumWriter<AnotherSampleRecord> writer =
new ReflectDatumWriter<AnotherSampleRecord>(schm);
ByteArrayOutputStream out = new ByteArrayOutputStream();
// keep record.a null and see if that works
Encoder e = factory.directBinaryEncoder(out, null);
AnotherSampleRecord a = new AnotherSampleRecord();
writer.write(a, e);
AnotherSampleRecord b = new AnotherSampleRecord(10);
writer.write(b, e);
e.flush();
ReflectDatumReader<AnotherSampleRecord> reader =
new ReflectDatumReader<AnotherSampleRecord>(schm);
ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
Decoder d = DecoderFactory.get().binaryDecoder(in, null);
AnotherSampleRecord decoded = reader.read(null, d);