chenghm123 commented on issue #358:
URL: https://github.com/apache/rocketmq-spring/issues/358#issuecomment-805855470
> ```java
> public class DefaultRocketMQListenerContainer implements InitializingBean,
> RocketMQListenerContainer, SmartLifecycle, ApplicationContextAware {
> // ……
>
> private Object doConvertMessage(MessageExt messageExt) {
> if (Objects.equals(messageType, MessageExt.class) ||
Objects.equals(messageType, org.apache.rocketmq.common.message.Message.class)) {
> return messageExt;
> } else {
> String str = new String(messageExt.getBody(),
Charset.forName(charset));
> if (Objects.equals(messageType, String.class)) {
> return str;
> } else {
> // If msgType not string, use objectMapper change it.
> try {
> if (messageType instanceof Class) {
> //if the messageType has not Generic Parameter
> return
this.getMessageConverter().fromMessage(MessageBuilder.withPayload(str).build(),
(Class<?>) messageType);
> } else {
> //if the messageType has Generic Parameter, then
use SmartMessageConverter#fromMessage with third parameter "conversionHint".
> //we have validate the MessageConverter is
SmartMessageConverter in this#getMethodParameter.
> return ((SmartMessageConverter)
this.getMessageConverter()).fromMessage(MessageBuilder.withPayload(str).build(),
(Class<?>) ((ParameterizedType) messageType).getRawType(), methodParameter);
> }
> } catch (Exception e) {
> log.info("convert failed. str:{}, msgType:{}", str,
messageType);
> throw new RuntimeException("cannot convert message to
" + messageType, e);
> }
> }
> }
> }
>
> // ……
> }
> ```
--
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.
For queries about this service, please contact Infrastructure at:
[email protected]