You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nifi.apache.org by pv...@apache.org on 2018/06/08 08:10:54 UTC

nifi git commit: NIFI-5281: If value is not valid according to the schema's CHOICE field, JSON Writer should write null value instead of throwing NullPointerException

Repository: nifi
Updated Branches:
  refs/heads/master 0e09b98b0 -> 49228aa5d


NIFI-5281: If value is not valid according to the schema's CHOICE  field, JSON Writer should write null value instead of throwing NullPointerException

Signed-off-by: Pierre Villard <pi...@gmail.com>

This closes #2772.


Project: http://git-wip-us.apache.org/repos/asf/nifi/repo
Commit: http://git-wip-us.apache.org/repos/asf/nifi/commit/49228aa5
Tree: http://git-wip-us.apache.org/repos/asf/nifi/tree/49228aa5
Diff: http://git-wip-us.apache.org/repos/asf/nifi/diff/49228aa5

Branch: refs/heads/master
Commit: 49228aa5dcbae5c4216310117daba586a63e6778
Parents: 0e09b98
Author: Mark Payne <ma...@hotmail.com>
Authored: Thu Jun 7 15:44:22 2018 -0400
Committer: Pierre Villard <pi...@gmail.com>
Committed: Fri Jun 8 10:07:43 2018 +0200

----------------------------------------------------------------------
 .../main/java/org/apache/nifi/json/WriteJsonResult.java  | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/nifi/blob/49228aa5/nifi-nar-bundles/nifi-standard-services/nifi-record-serialization-services-bundle/nifi-record-serialization-services/src/main/java/org/apache/nifi/json/WriteJsonResult.java
----------------------------------------------------------------------
diff --git a/nifi-nar-bundles/nifi-standard-services/nifi-record-serialization-services-bundle/nifi-record-serialization-services/src/main/java/org/apache/nifi/json/WriteJsonResult.java b/nifi-nar-bundles/nifi-standard-services/nifi-record-serialization-services-bundle/nifi-record-serialization-services/src/main/java/org/apache/nifi/json/WriteJsonResult.java
index c596ae2..d113f8d 100755
--- a/nifi-nar-bundles/nifi-standard-services/nifi-record-serialization-services-bundle/nifi-record-serialization-services/src/main/java/org/apache/nifi/json/WriteJsonResult.java
+++ b/nifi-nar-bundles/nifi-standard-services/nifi-record-serialization-services-bundle/nifi-record-serialization-services/src/main/java/org/apache/nifi/json/WriteJsonResult.java
@@ -55,7 +55,6 @@ public class WriteJsonResult extends AbstractRecordSetWriter implements RecordSe
     private final RecordSchema recordSchema;
     private final JsonFactory factory = new JsonFactory();
     private final JsonGenerator generator;
-    private final OutputStream out;
     private final NullSuppression nullSuppression;
     private final OutputGrouping outputGrouping;
     private final Supplier<DateFormat> LAZY_DATE_FORMAT;
@@ -69,7 +68,6 @@ public class WriteJsonResult extends AbstractRecordSetWriter implements RecordSe
         this.logger = logger;
         this.recordSchema = recordSchema;
         this.schemaAccess = schemaAccess;
-        this.out = out;
         this.nullSuppression = nullSuppression;
         this.outputGrouping = outputGrouping;
 
@@ -270,14 +268,19 @@ public class WriteJsonResult extends AbstractRecordSetWriter implements RecordSe
     }
 
     @SuppressWarnings("unchecked")
-    private void writeValue(final JsonGenerator generator, final Object value, final String fieldName, final DataType dataType)
-        throws JsonGenerationException, IOException {
+    private void writeValue(final JsonGenerator generator, final Object value, final String fieldName, final DataType dataType) throws JsonGenerationException, IOException {
         if (value == null) {
             generator.writeNull();
             return;
         }
 
         final DataType chosenDataType = dataType.getFieldType() == RecordFieldType.CHOICE ? DataTypeUtils.chooseDataType(value, (ChoiceDataType) dataType) : dataType;
+        if (chosenDataType == null) {
+            logger.debug("Could not find a suitable field type in the CHOICE for field {} and value {}; will use null value", new Object[] {fieldName, value});
+            generator.writeNull();
+            return;
+        }
+
         final Object coercedValue = DataTypeUtils.convertType(value, chosenDataType, LAZY_DATE_FORMAT, LAZY_TIME_FORMAT, LAZY_TIMESTAMP_FORMAT, fieldName);
         if (coercedValue == null) {
             generator.writeNull();