gnodet-bot commented on code in PR #30475:
URL: https://github.com/apache/camel/pull/30475#discussion_r4639427654


##########
components/camel-jackson/src/main/java/org/apache/camel/component/jackson/transform/JsonDataTypeTransformer.java:
##########
@@ -68,10 +71,12 @@ public void transform(Message message, DataType fromType, 
DataType toType) {
                 // a Map or a List has no class to write it as: it becomes a 
Json object or array
                 marshalled = Json.mapper().writeValueAsBytes(body);
             } else if (!hasContentClass && isText(body)) {
-                // read as text with the exchange charset: a Json object or 
array is kept, and any other text, also a
-                // Json number, boolean, null or quoted string, becomes a Json 
string
+                // read as text with the exchange charset: a Json object or 
array is kept, and so is a Json number,
+                // boolean, null or quoted string when the Content-Type says 
the text is Json; any other text becomes a
+                // Json string
                 String text = message.getMandatoryBody(String.class);
-                marshalled = Json.isJson(text) ? 
text.getBytes(StandardCharsets.UTF_8) : Json.mapper().writeValueAsBytes(text);
+                marshalled = Json.isJson(text) || isJsonContent(message) && 
isJsonValue(text)
+                        ? text.getBytes(StandardCharsets.UTF_8) : 
Json.mapper().writeValueAsBytes(text);

Review Comment:
   Nit: the mix of `||`, `&&`, and `?:` without parentheses requires recalling 
Java's precedence table. Adding explicit parentheses makes the intent 
immediately clear to future readers. The logic is correct as-is.
   
   ```suggestion
                   marshalled = (Json.isJson(text) || isJsonContent(message) && 
isJsonValue(text))
                           ? text.getBytes(StandardCharsets.UTF_8) : 
Json.mapper().writeValueAsBytes(text);
   ```



##########
components/camel-jackson3/src/main/java/org/apache/camel/component/jackson3/transform/JsonDataTypeTransformer.java:
##########
@@ -68,10 +71,12 @@ public void transform(Message message, DataType fromType, 
DataType toType) {
                 // a Map or a List has no class to write it as: it becomes a 
Json object or array
                 marshalled = Json.mapper().writeValueAsBytes(body);
             } else if (!hasContentClass && isText(body)) {
-                // read as text with the exchange charset: a Json object or 
array is kept, and any other text, also a
-                // Json number, boolean, null or quoted string, becomes a Json 
string
+                // read as text with the exchange charset: a Json object or 
array is kept, and so is a Json number,
+                // boolean, null or quoted string when the Content-Type says 
the text is Json; any other text becomes a
+                // Json string
                 String text = message.getMandatoryBody(String.class);
-                marshalled = Json.isJson(text) ? 
text.getBytes(StandardCharsets.UTF_8) : Json.mapper().writeValueAsBytes(text);
+                marshalled = Json.isJson(text) || isJsonContent(message) && 
isJsonValue(text)
+                        ? text.getBytes(StandardCharsets.UTF_8) : 
Json.mapper().writeValueAsBytes(text);

Review Comment:
   Same readability nit as `camel-jackson` — explicit parentheses around the 
boolean condition. Correct as-is; this is for future readers.
   
   ```suggestion
                   marshalled = (Json.isJson(text) || isJsonContent(message) && 
isJsonValue(text))
                           ? text.getBytes(StandardCharsets.UTF_8) : 
Json.mapper().writeValueAsBytes(text);
   ```



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