use of org.springframework.messaging.converter.MessageConversionException in project spring-framework by spring-projects.
the class AbstractMessageReceivingTemplate method doConvert.
/**
* Convert from the given message to the given target class.
* @param message the message to convert
* @param targetClass the target class to convert the payload to
* @return the converted payload of the reply message (never {@code null})
*/
@SuppressWarnings("unchecked")
@Nullable
protected <T> T doConvert(Message<?> message, Class<T> targetClass) {
MessageConverter messageConverter = getMessageConverter();
T value = (T) messageConverter.fromMessage(message, targetClass);
if (value == null) {
throw new MessageConversionException(message, "Unable to convert payload [" + message.getPayload() + "] to type [" + targetClass + "] using converter [" + messageConverter + "]");
}
return value;
}
Aggregations