public Record build() {
Record record;
try {
record = new GenericData.Record(schema());
} catch (Exception e) {
throw new AvroRuntimeException(e);
}
for (Field field : fields()) {
Object value;
try {
value = getWithDefault(field);
} catch(IOException e) {
throw new AvroRuntimeException(e);
}
if (value != null) {
record.put(field.pos(), value);
}
}