davsclaus commented on code in PR #30475:
URL: https://github.com/apache/camel/pull/30475#discussion_r4639615169


##########
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:
   Fixed in 74d4e160162e: parentheses around the condition.
   
   _Claude Code on behalf of davsclaus_



##########
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:
   Fixed in 74d4e160162e, the same as in camel-jackson.
   
   _Claude Code on behalf of davsclaus_



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