oscerd commented on code in PR #28950:
URL: https://github.com/apache/camel/pull/28950#discussion_r4448219289


##########
components/camel-alibaba/camel-alibaba-mns/src/main/java/org/apache/camel/component/alibaba/mns/MNSUtils.java:
##########
@@ -121,6 +129,46 @@ public static String resolveMessageBody(Exchange exchange) 
{
         return exchange.getMessage().getBody(String.class);
     }
 
+    /**
+     * Sets the body of the exchange as the body of the MNS message to send or 
publish. Text is sent as it is. Bytes, a
+     * stream or a file are sent as their bytes, so that binary data is not 
changed. A body that has no bytes, such as a
+     * number, a Map, a collection or a POJO, is sent as its text.
+     */
+    public static void setMessageBody(Exchange exchange, BaseMessage message) {
+        Object body = exchange.getMessage().getBody();
+        // not a collection or an array other than byte[], which the type 
converter would turn into an array of bytes
+        // element by element (failing for a List of String) instead of 
sending their text
+        if (body != null && !(body instanceof String) && !(body instanceof 
Collection<?>)
+                && !(body.getClass().isArray() && !(body instanceof byte[]))) {

Review Comment:
   Thanks. I kept the guard to collections and arrays other than `byte[]`, as 
in the eventbridge fix, for the reason Claus gives in his review: core has no 
`Map` to `byte[]` converter, so a `Map` reaches `toString()` today 
(`MNSProducerBodyTest` covers it). The only converter that could apply is the 
opt-in Jackson fallback converter, which handles a POJO the same way, and when 
a user turns it on, sending the JSON bytes of a `Map` is a reasonable result. 
Guarding `Map` alone would treat it differently from a POJO.
   
   _Claude Code on behalf of Andrea Cosentino (oscerd)_
   



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