接口 MessageConverter
- 所有已知子接口:
SmartMessageConverter
- 所有已知实现类:
AbstractMessageConverter,ByteArrayMessageConverter,CompositeMessageConverter,GenericMessageConverter,MappingJackson2MessageConverter,MarshallingMessageConverter,ProtobufJsonFormatMessageConverter,ProtobufMessageConverter,SimpleMessageConverter,StringMessageConverter
public interface MessageConverter
A converter to turn the payload of aMessagefrom serialized form to a typed Object and vice versa. TheMessageHeaders.CONTENT_TYPEmessage header may be used to specify the media type of the message content.- 从以下版本开始:
- 4.0
- 作者:
- Mark Fisher, Rossen Stoyanchev
方法概要
所有方法 实例方法 抽象方法 修饰符和类型 方法 说明 ObjectfromMessage(Message<?> message, Class<?> targetClass)Convert the payload of aMessagefrom a serialized form to a typed Object of the specified target class.Message<?>toMessage(Object payload, MessageHeaders headers)Create aMessagewhose payload is the result of converting the given payload Object to serialized form.
方法详细资料
fromMessage
@Nullable Object fromMessage(Message<?> message, Class<?> targetClass)
Convert the payload of aMessagefrom a serialized form to a typed Object of the specified target class. TheMessageHeaders.CONTENT_TYPEheader should indicate the MIME type to convert from.If the converter does not support the specified media type or cannot perform the conversion, it should return
null.- 参数:
message- the input messagetargetClass- the target class for the conversion- 返回:
- the result of the conversion, or
nullif the converter cannot perform the conversion
toMessage
@Nullable Message<?> toMessage(Object payload, @Nullable MessageHeaders headers)
Create aMessagewhose payload is the result of converting the given payload Object to serialized form. The optionalMessageHeadersparameter may contain aMessageHeaders.CONTENT_TYPEheader to specify the target media type for the conversion and it may contain additional headers to be added to the message.If the converter does not support the specified media type or cannot perform the conversion, it should return
null.- 参数:
payload- the Object to convertheaders- optional headers for the message (may benull)- 返回:
- the new message, or
nullif the converter does not support the Object type or the target media type