exceptionfactory commented on code in PR #7231:
URL: https://github.com/apache/nifi/pull/7231#discussion_r1205529807
##########
nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/AttributesToJSON.java:
##########
@@ -240,24 +281,51 @@ public void onTrigger(ProcessContext context,
ProcessSession session) throws Pro
return;
}
- final Map<String, String> atrList =
buildAttributesMapForFlowFile(original, attributes, attributesToRemove,
nullValueForEmptyString, pattern);
+ final Map<String, Object> atrList =
buildAttributesMapForFlowFile(original, attributes, attributesToRemove,
nullValueForEmptyString, pattern);
try {
+ Map<String, Object> asJson = getAsJson(atrList);
if (destinationContent) {
FlowFile conFlowfile = session.write(original, (in, out) -> {
try (OutputStream outputStream = new
BufferedOutputStream(out)) {
-
outputStream.write(objectMapper.writeValueAsBytes(atrList));
+
outputStream.write(objectMapper.writeValueAsBytes(asJson));
}
});
conFlowfile = session.putAttribute(conFlowfile,
CoreAttributes.MIME_TYPE.key(), APPLICATION_JSON);
session.transfer(conFlowfile, REL_SUCCESS);
} else {
- FlowFile atFlowfile = session.putAttribute(original,
JSON_ATTRIBUTE_NAME, objectMapper.writeValueAsString(atrList));
+ FlowFile atFlowfile = session.putAttribute(original,
JSON_ATTRIBUTE_NAME, objectMapper.writeValueAsString(asJson));
session.transfer(atFlowfile, REL_SUCCESS);
}
} catch (JsonProcessingException e) {
getLogger().error(e.getMessage());
session.transfer(original, REL_FAILURE);
}
}
+
+ private Map<String, Object> getAsJson(Map<String, Object> atrList) throws
JsonProcessingException {
+ if(JsonHandlingStrategy.ESCAPED_STRING.equals(jsonHandlingStrategy)) {
+ return atrList;
+ }
+
+ Map<String, Object> asJson = new HashMap<>();
Review Comment:
Thanks, if you could push that change as well, that would be helpful.
--
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]