From 382eef2183192357c3823c207f1835711f57688c Mon Sep 17 00:00:00 2001 From: Steve Champagne Date: Fri, 12 May 2017 17:32:14 +0000 Subject: [PATCH] NIFI-3879: Allow null Avro default values - Avro uses their own class for null values, so a standard check against null isn't picking them up. This closes #1792. --- .../src/main/java/org/apache/nifi/avro/AvroTypeUtil.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) 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 bd5e8e46d0..8ded9bcbd9 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 @@ -25,6 +25,7 @@ import org.apache.avro.generic.GenericData; import org.apache.avro.generic.GenericFixed; import org.apache.avro.generic.GenericRecord; import org.apache.avro.util.Utf8; +import org.apache.avro.JsonProperties; import org.apache.nifi.schema.access.SchemaNotFoundException; import org.apache.nifi.serialization.SimpleRecordSchema; import org.apache.nifi.serialization.record.DataType; @@ -205,7 +206,11 @@ public class AvroTypeUtil { final String fieldName = field.name(); final DataType dataType = AvroTypeUtil.determineDataType(field.schema()); - recordFields.add(new RecordField(fieldName, dataType, field.defaultVal(), field.aliases())); + if (field.defaultVal() == JsonProperties.NULL_VALUE) { + recordFields.add(new RecordField(fieldName, dataType, field.aliases())); + } else { + recordFields.add(new RecordField(fieldName, dataType, field.defaultVal(), field.aliases())); + } } final RecordSchema recordSchema = new SimpleRecordSchema(recordFields, schemaText, AVRO_SCHEMA_FORMAT, schemaId);