Search in sources :

Example 16 with MessageConversionException

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;
}
Also used : MessageConversionException(org.springframework.messaging.converter.MessageConversionException) MessageConverter(org.springframework.messaging.converter.MessageConverter) Nullable(org.springframework.lang.Nullable)

Aggregations

MessageConversionException (org.springframework.messaging.converter.MessageConversionException)16 IOException (java.io.IOException)3 Test (org.junit.Test)3 MessageHandlingException (org.springframework.messaging.MessageHandlingException)3 MessageConverter (org.springframework.messaging.converter.MessageConverter)3 SmartMessageConverter (org.springframework.messaging.converter.SmartMessageConverter)3 MimeType (org.springframework.util.MimeType)3 Schema (org.apache.avro.Schema)2 SpringApplicationBuilder (org.springframework.boot.builder.SpringApplicationBuilder)2 InputDestination (org.springframework.cloud.stream.binder.test.InputDestination)2 TestChannelBinder (org.springframework.cloud.stream.binder.test.TestChannelBinder)2 ApplicationContext (org.springframework.context.ApplicationContext)2 MessageHeaders (org.springframework.messaging.MessageHeaders)2 JavaType (com.fasterxml.jackson.databind.JavaType)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 Type (java.lang.reflect.Type)1 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)1 TransformerException (javax.xml.transform.TransformerException)1 XPathExpressionException (javax.xml.xpath.XPathExpressionException)1