You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@nifi.apache.org by "Peter Gyori (Jira)" <ji...@apache.org> on 2021/02/16 18:58:00 UTC

[jira] [Commented] (NIFI-7969) XMLReader / ValidateRecord: arrays are not read correctly

    [ https://issues.apache.org/jira/browse/NIFI-7969?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17285423#comment-17285423 ] 

Peter Gyori commented on NIFI-7969:
-----------------------------------

I created a pull request for this issue. The CI builds and tests still need to finish.
Setting the new "Force Types From Schema" property to "true" on the ValidateRecord processor solves this issue. To see what other effect this property has please check the Additional Details page of the ValidateRecord processor's documentation that has just been updated in this pull request.
https://github.com/apache/nifi/pull/4825

> 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.9.0, 1.12.0
>            Reporter: Vesa Sokka
>            Assignee: Peter Gyori
>            Priority: Major
>              Labels: records, validation, xml
>         Attachments: image-2020-10-30-13-09-08-833.png, xml_array.xml
>
>          Time Spent: 10m
>  Remaining Estimate: 0h
>
> 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?*
>  
> Template attached:
> xml_array.xml
>   



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