davsclaus commented on code in PR #28950:
URL: https://github.com/apache/camel/pull/28950#discussion_r4448205895
##########
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:
Not needed, I think: core has no `Map` to `byte[]` converter, so a `Map`
already ends in `toString()`, as the docs say. Only the opt-in Jackson fallback
converter would turn it into JSON bytes, and it does the same for a POJO, which
is a reasonable outcome when a user has enabled it. Guarding `Map` alone would
treat it differently from a POJO. Resolving; see the review for the details.
_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]