接口 HttpMessageConverter<T>
- 类型参数:
T
- the converted object type
- 所有已知子接口:
GenericHttpMessageConverter<T>
- 所有已知实现类:
AbstractGenericHttpMessageConverter
,AbstractHttpMessageConverter
,AbstractJackson2HttpMessageConverter
,AbstractJaxb2HttpMessageConverter
,AbstractJsonHttpMessageConverter
,AbstractWireFeedHttpMessageConverter
,AbstractXmlHttpMessageConverter
,AllEncompassingFormHttpMessageConverter
,AtomFeedHttpMessageConverter
,BufferedImageHttpMessageConverter
,ByteArrayHttpMessageConverter
,FormHttpMessageConverter
,GsonHttpMessageConverter
,Jaxb2CollectionHttpMessageConverter
,Jaxb2RootElementHttpMessageConverter
,JsonbHttpMessageConverter
,MappingJackson2CborHttpMessageConverter
,MappingJackson2HttpMessageConverter
,MappingJackson2SmileHttpMessageConverter
,MappingJackson2XmlHttpMessageConverter
,MarshallingHttpMessageConverter
,ObjectToStringHttpMessageConverter
,ProtobufHttpMessageConverter
,ProtobufJsonFormatHttpMessageConverter
,ResourceHttpMessageConverter
,ResourceRegionHttpMessageConverter
,RssChannelHttpMessageConverter
,SourceHttpMessageConverter
,StringHttpMessageConverter
public interface HttpMessageConverter<T>
Strategy interface for converting from and to HTTP requests and responses.- 从以下版本开始:
- 3.0
- 作者:
- Arjen Poutsma, Juergen Hoeller
方法概要
所有方法 实例方法 抽象方法 修饰符和类型 方法 说明 boolean
canRead(Class<?> clazz, MediaType mediaType)
Indicates whether the given class can be read by this converter.boolean
canWrite(Class<?> clazz, MediaType mediaType)
Indicates whether the given class can be written by this converter.List<MediaType>
getSupportedMediaTypes()
Return the list ofMediaType
objects supported by this converter.T
read(Class<? extends T> clazz, HttpInputMessage inputMessage)
Read an object of the given type from the given input message, and returns it.void
write(T t, MediaType contentType, HttpOutputMessage outputMessage)
Write an given object to the given output message.
方法详细资料
canRead
boolean canRead(Class<?> clazz, @Nullable MediaType mediaType)
Indicates whether the given class can be read by this converter.- 参数:
clazz
- the class to test for readabilitymediaType
- the media type to read (can benull
if not specified); typically the value of aContent-Type
header.- 返回:
true
if readable;false
otherwise
canWrite
boolean canWrite(Class<?> clazz, @Nullable MediaType mediaType)
Indicates whether the given class can be written by this converter.- 参数:
clazz
- the class to test for writabilitymediaType
- the media type to write (can benull
if not specified); typically the value of anAccept
header.- 返回:
true
if writable;false
otherwise
getSupportedMediaTypes
List<MediaType> getSupportedMediaTypes()
Return the list ofMediaType
objects supported by this converter.- 返回:
- the list of supported media types, potentially an immutable copy
read
T read(Class<? extends T> clazz, HttpInputMessage inputMessage) throws IOException, HttpMessageNotReadableException
Read an object of the given type from the given input message, and returns it.- 参数:
clazz
- the type of object to return. This type must have previously been passed to thecanRead
method of this interface, which must have returnedtrue
.inputMessage
- the HTTP input message to read from- 返回:
- the converted object
- 抛出:
IOException
- in case of I/O errorsHttpMessageNotReadableException
- in case of conversion errors
write
void write(T t, @Nullable MediaType contentType, HttpOutputMessage outputMessage) throws IOException, HttpMessageNotWritableException
Write an given object to the given output message.- 参数:
t
- the object to write to the output message. The type of this object must have previously been passed to thecanWrite
method of this interface, which must have returnedtrue
.contentType
- the content type to use when writing. May benull
to indicate that the default content type of the converter must be used. If notnull
, this media type must have previously been passed to thecanWrite
method of this interface, which must have returnedtrue
.outputMessage
- the message to write to- 抛出:
IOException
- in case of I/O errorsHttpMessageNotWritableException
- in case of conversion errors