Uploaded image for project: 'Apache NiFi'
  1. Apache NiFi
  2. NIFI-7969

XMLReader / ValidateRecord: arrays are not read correctly

    XMLWordPrintableJSON

    Details

      Description

      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.

      Both examples have same schema;

      { 
       "namespace": "nifi",
       "name": "test",
       "type": "record",
       "fields": [ 
         { "name": "array_field", 
           "type": 
           { "type": "array", "items": "string" } 
         }
       ]
      }
      

       
       

      Example 1 (success)

      <record> 
       <array_field>content1</array_field>
       <array_field>content2</array_field>
      </record> 

      --> valid:

      [{"array_field":["content1","content2"]}]
      

       

      Example 2 (invalid):

      Same as example 1, but the second array_field removed

      <record> 
       <array_field>content1</array_field>
      </record>
      

      --> invalid 

      [{"array_field":"content1"}]

       

       

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

       

      Template attached:

      xml_array.xml
       

        Attachments

        1. image-2020-10-30-13-09-08-833.png
          287 kB
          Vesa Sokka
        2. xml_array.xml
          35 kB
          Vesa Sokka

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              vesako Vesa Sokka
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated: