pgyori commented on code in PR #5964:
URL: https://github.com/apache/nifi/pull/5964#discussion_r856335526
##########
nifi-nar-bundles/nifi-standard-services/nifi-record-serialization-services-bundle/nifi-record-serialization-services/src/main/java/org/apache/nifi/xml/XMLRecordReader.java:
##########
@@ -354,54 +344,32 @@ private Object parseUnknownField(StartElement
startElement, boolean dropUnknown,
}
}
- private Record parseRecord(StartElement startElement, RecordSchema schema,
boolean coerceTypes, boolean dropUnknown) throws XMLStreamException,
MalformedRecordException {
- final Map<String, Object> recordValues = new HashMap<>();
-
- // parse attributes
+ private void parseAttributesForUnknownField(StartElement startElement,
RecordSchema schema, boolean dropUnknown, Map<String, Object> recordValues) {
final Iterator iterator = startElement.getAttributes();
while (iterator.hasNext()) {
final Attribute attribute = (Attribute) iterator.next();
final String attributeName = attribute.getName().toString();
- final String targetFieldName = attributePrefix == null ?
attributeName : attributePrefix + attributeName;
-
if (dropUnknown) {
- final Optional<RecordField> field =
schema.getField(attributeName);
- if (field.isPresent()){
-
- // dropUnknown == true && coerceTypes == true
- if (coerceTypes) {
- final Object value;
- final DataType dataType = field.get().getDataType();
- if ((value = parseStringForType(attribute.getValue(),
attributeName, dataType)) != null) {
- recordValues.put(targetFieldName, value);
- }
-
- // dropUnknown == true && coerceTypes == false
- } else {
- recordValues.put(targetFieldName,
attribute.getValue());
- }
- }
- } else {
-
- // dropUnknown == false && coerceTypes == true
- if (coerceTypes) {
- final Object value;
+ if (schema != null) {
final Optional<RecordField> field =
schema.getField(attributeName);
if (field.isPresent()){
- if ((value = parseStringForType(attribute.getValue(),
attributeName, field.get().getDataType())) != null) {
- recordValues.put(targetFieldName, value);
- }
- } else {
- recordValues.put(targetFieldName,
attribute.getValue());
+ recordValues.put(attributePrefix == null ?
attributeName : attributePrefix + attributeName, attribute.getValue());
Review Comment:
Thank you for pointing that out. The fix is coming in my next commit.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]