diff --git a/nifi-nar-bundles/nifi-extension-utils/nifi-record-utils/nifi-avro-record-utils/src/main/java/org/apache/nifi/avro/AvroTypeUtil.java b/nifi-nar-bundles/nifi-extension-utils/nifi-record-utils/nifi-avro-record-utils/src/main/java/org/apache/nifi/avro/AvroTypeUtil.java index 1417e67f15..76438c5212 100644 --- a/nifi-nar-bundles/nifi-extension-utils/nifi-record-utils/nifi-avro-record-utils/src/main/java/org/apache/nifi/avro/AvroTypeUtil.java +++ b/nifi-nar-bundles/nifi-extension-utils/nifi-record-utils/nifi-avro-record-utils/src/main/java/org/apache/nifi/avro/AvroTypeUtil.java @@ -273,6 +273,15 @@ public class AvroTypeUtil { rec.put(fieldName, converted); } + // see if the Avro schema has any fields that aren't in the RecordSchema, and if those fields have a default + // value then we want to populate it in the GenericRecord being produced + for (final Field field : avroSchema.getFields()) { + final Optional recordField = recordSchema.getField(field.name()); + if (!recordField.isPresent() && rec.get(field.name()) == null && field.defaultVal() != null) { + rec.put(field.name(), field.defaultVal()); + } + } + return rec; }