ReggieCarey commented on a change in pull request #681:
URL: https://github.com/apache/camel-kamelets/pull/681#discussion_r780368069



##########
File path: 
library/camel-kamelets-utils/src/main/java/org/apache/camel/kamelets/utils/transform/ExtractField.java
##########
@@ -27,11 +27,16 @@
 
 public class ExtractField {
 
-    public void process(@ExchangeProperty("field") String field, Exchange ex) {
+    public void process(@ExchangeProperty("field") String field, 
@ExchangeProperty("headerOutput") boolean headerOutput, Exchange ex) {
+        final String EXTRACTED_FIELD_HEADER = "CamelKameletsExtractFieldName";
         ObjectMapper mapper = new ObjectMapper();
         JsonNode jsonNodeBody = ex.getMessage().getBody(JsonNode.class);
         Map<Object, Object> body = mapper.convertValue(jsonNodeBody, new 
TypeReference<Map<Object, Object>>(){});
-        ex.getMessage().setBody(body.get(field));
+        if (!headerOutput) {
+            ex.getMessage().setBody(body.get(field));
+        } else {
+            ex.getMessage().setHeader(EXTRACTED_FIELD_HEADER, body.get(field));

Review comment:
       As per my comments in the issue, maybe this is better in line 38?
   
   ex.getMessage.setHeader(sanitized(headerOutput), body.get(field));
   
   Where ```String sanitized(String headerOutput)``` does its best to ensure a 
valid headerName that does not collide with existing headers.




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