tpalfy commented on a change in pull request #3724: NIFI-6640 - UNION/CHOICE types not handled correctly URL: https://github.com/apache/nifi/pull/3724#discussion_r324578085
########## File path: nifi-nar-bundles/nifi-extension-utils/nifi-record-utils/nifi-avro-record-utils/src/main/java/org/apache/nifi/avro/AvroTypeUtil.java ########## @@ -877,6 +878,18 @@ private static Object convertToAvroObject(final Object rawValue, final Schema fi */ private static Object convertUnionFieldValue(final Object originalValue, final Schema fieldSchema, final Function<Schema, Object> conversion, final String fieldName) { boolean foundNonNull = false; + + Optional<Schema> mostSuitableType = DataTypeUtils.findMostSuitableType( + originalValue, + fieldSchema.getTypes().stream().filter(schema -> schema.getType() != Type.NULL).collect(Collectors.toList()), + subSchema -> AvroTypeUtil.determineDataType(subSchema) + ); + if (mostSuitableType.isPresent()) { + Object convertedVAlue = conversion.apply(mostSuitableType.get()); Review comment: Yeah, I guess even my previous reasoning doesn't hold well as this method already has multiple return statements. (Although during debugging it still can be useful to just add a break point and see immediately the returned value, some simplification could be better.) ---------------------------------------------------------------- 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. For queries about this service, please contact Infrastructure at: us...@infra.apache.org With regards, Apache Git Services