Vesa Sokka created NIFI-7969:
--------------------------------

             Summary: XMLReader / ValidateRecord: arrays are not read correctly
                 Key: NIFI-7969
                 URL: https://issues.apache.org/jira/browse/NIFI-7969
             Project: Apache NiFi
          Issue Type: Bug
          Components: Core Framework, Extensions
    Affects Versions: 1.12.0, 1.9.0
            Reporter: Vesa Sokka
         Attachments: image-2020-10-30-13-09-08-833.png

I'm trying to convert XML to JSON with ValidateRecord using XMLReader. Arrays 
with multiple elements work fine, but an *array with only one element fails*.

 

In XMLReader docs it says clearly:

_"If a field in a schema is embedded in an array, the *reader expects zero, one 
or more* occurrences of the field in a record. "_

But in fact an array with only one field is transferred to "invalid" with an 
error message:

"Record #1 is invalid due to:
 content1 is not a valid value for /array_field: Value is of type 
java.lang.String but was expected to be of type ARRAY[STRING]"

 

examples modified from:
 
[https://nifi.apache.org/docs/nifi-docs/components/org.apache.nifi/nifi-record-serialization-services-nar/1.12.1/org.apache.nifi.xml.XMLReader/additionalDetails.]

!image-2020-10-30-13-09-08-833.png|height=250!

_Both examples have same schema_;
{code:json}
{ 
 "namespace": "nifi",
 "name": "test",
 "type": "record",
 "fields": [ 
   { "name": "array_field", 
     "type": 
     { "type": "array", "items": "string" } 
   }
 ]
}
{code}
 
  

*Example 1* (success)
{code:xml}
<record> 
 <array_field>content1</array_field>
 <array_field>content2</array_field>
</record> {code}
--> *valid*+:+
{code:json}
[{"array_field":["content1","content2"]}]
{code}
 

*Example 2* (invalid):

Same as example 1, but the second array_field removed
{code:xml}
<record> 
 <array_field>content1</array_field>
</record>
{code}
--> *invalid* 
{code:json}
[{"array_field":"content1"}]{code}
 

 

*Seems to be a BUG or is this an error in the processor documentation?*

 

 
  



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to