exceptionfactory commented on code in PR #8156:
URL: https://github.com/apache/nifi/pull/8156#discussion_r1425826183


##########
nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/AttributesToJSON.java:
##########
@@ -282,17 +295,21 @@ public void onTrigger(ProcessContext context, 
ProcessSession session) throws Pro
         final Map<String, Object> atrList = 
buildAttributesMapForFlowFile(original, attributes, attributesToRemove, 
nullValueForEmptyString, pattern);
 
         try {
-            Map<String, Object> formattedAttributes = 
getFormattedAttributes(atrList);
+            final Map<String, Object> formattedAttributes = 
getFormattedAttributes(atrList);
             if (destinationContent) {
                 FlowFile conFlowfile = session.write(original, (in, out) -> {
                     try (OutputStream outputStream = new 
BufferedOutputStream(out)) {
-                        
outputStream.write(objectMapper.writeValueAsBytes(formattedAttributes));
+                        if(prettyPrint) {
+                            
outputStream.write(OBJECT_MAPPER.writerWithDefaultPrettyPrinter().writeValueAsBytes(formattedAttributes));

Review Comment:
   Rather than calling `writerWithDefaultPrettyPrinter()` for every invocation, 
it would be better to assign the appropriate `ObjectWriter()` and then the 
`onTrigger` method does not need to be conditional.



##########
nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/AttributesToJSON.java:
##########
@@ -282,17 +295,21 @@ public void onTrigger(ProcessContext context, 
ProcessSession session) throws Pro
         final Map<String, Object> atrList = 
buildAttributesMapForFlowFile(original, attributes, attributesToRemove, 
nullValueForEmptyString, pattern);
 
         try {
-            Map<String, Object> formattedAttributes = 
getFormattedAttributes(atrList);
+            final Map<String, Object> formattedAttributes = 
getFormattedAttributes(atrList);
             if (destinationContent) {
                 FlowFile conFlowfile = session.write(original, (in, out) -> {
                     try (OutputStream outputStream = new 
BufferedOutputStream(out)) {
-                        
outputStream.write(objectMapper.writeValueAsBytes(formattedAttributes));
+                        if(prettyPrint) {
+                            
outputStream.write(OBJECT_MAPPER.writerWithDefaultPrettyPrinter().writeValueAsBytes(formattedAttributes));
+                        } else {
+                            
outputStream.write(OBJECT_MAPPER.writeValueAsBytes(formattedAttributes));
+                        }

Review Comment:
   This is a good opportunity to improve the behavior, as the Jackson Writer 
can write to an OutputStream, as opposed to writing the value as bytes.



-- 
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]

Reply via email to