类 AbstractGenericHttpMessageConverter<T>
- java.lang.Object
- org.springframework.http.converter.AbstractHttpMessageConverter<T>
- org.springframework.http.converter.AbstractGenericHttpMessageConverter<T>
- 类型参数:
T
- the converted object type
- 所有已实现的接口:
GenericHttpMessageConverter<T>
,HttpMessageConverter<T>
- 直接已知子类:
AbstractJackson2HttpMessageConverter
,AbstractJsonHttpMessageConverter
,ResourceRegionHttpMessageConverter
public abstract class AbstractGenericHttpMessageConverter<T> extends AbstractHttpMessageConverter<T> implements GenericHttpMessageConverter<T>
Abstract base class for mostGenericHttpMessageConverter
implementations.- 从以下版本开始:
- 4.2
- 作者:
- Sebastien Deleuze, Juergen Hoeller
字段概要
从类继承的字段 org.springframework.http.converter.AbstractHttpMessageConverter
logger
构造器概要
构造器 限定符 构造器 说明 protected
AbstractGenericHttpMessageConverter()
Construct anAbstractGenericHttpMessageConverter
with no supported media types.protected
AbstractGenericHttpMessageConverter(MediaType supportedMediaType)
Construct anAbstractGenericHttpMessageConverter
with one supported media type.protected
AbstractGenericHttpMessageConverter(MediaType... supportedMediaTypes)
Construct anAbstractGenericHttpMessageConverter
with multiple supported media type.
方法概要
所有方法 实例方法 抽象方法 具体方法 修饰符和类型 方法 说明 boolean
canRead(Type type, Class<?> contextClass, MediaType mediaType)
Indicates whether the given type can be read by this converter.boolean
canWrite(Type type, Class<?> clazz, MediaType mediaType)
Indicates whether the given class can be written by this converter.protected boolean
supports(Class<?> clazz)
Indicates whether the given class is supported by this converter.void
write(T t, Type type, MediaType contentType, HttpOutputMessage outputMessage)
This implementation sets the default headers by callingAbstractHttpMessageConverter.addDefaultHeaders(org.springframework.http.HttpHeaders, T, org.springframework.http.MediaType)
, and then callswriteInternal(T, org.springframework.http.HttpOutputMessage)
.protected abstract void
writeInternal(T t, Type type, HttpOutputMessage outputMessage)
Abstract template method that writes the actual body.protected void
writeInternal(T t, HttpOutputMessage outputMessage)
Abstract template method that writes the actual body.从类继承的方法 org.springframework.http.converter.AbstractHttpMessageConverter
addDefaultHeaders, canRead, canRead, canWrite, canWrite, getContentLength, getDefaultCharset, getDefaultContentType, getSupportedMediaTypes, read, readInternal, setDefaultCharset, setSupportedMediaTypes, write
从类继承的方法 java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
从接口继承的方法 org.springframework.http.converter.GenericHttpMessageConverter
read
从接口继承的方法 org.springframework.http.converter.HttpMessageConverter
canRead, canWrite, getSupportedMediaTypes, read, write
构造器详细资料
AbstractGenericHttpMessageConverter
protected AbstractGenericHttpMessageConverter()
Construct anAbstractGenericHttpMessageConverter
with no supported media types.
AbstractGenericHttpMessageConverter
protected AbstractGenericHttpMessageConverter(MediaType supportedMediaType)
Construct anAbstractGenericHttpMessageConverter
with one supported media type.- 参数:
supportedMediaType
- the supported media type
AbstractGenericHttpMessageConverter
protected AbstractGenericHttpMessageConverter(MediaType... supportedMediaTypes)
Construct anAbstractGenericHttpMessageConverter
with multiple supported media type.- 参数:
supportedMediaTypes
- the supported media types
方法详细资料
supports
protected boolean supports(Class<?> clazz)
从类复制的说明:AbstractHttpMessageConverter
Indicates whether the given class is supported by this converter.- 指定者:
supports
在类中AbstractHttpMessageConverter<T>
- 参数:
clazz
- the class to test for support- 返回:
true
if supported;false
otherwise
canRead
public boolean canRead(Type type, @Nullable Class<?> contextClass, @Nullable MediaType mediaType)
从接口复制的说明:GenericHttpMessageConverter
Indicates whether the given type can be read by this converter. This method should perform the same checks thanHttpMessageConverter.canRead(Class, MediaType)
with additional ones related to the generic type.- 指定者:
canRead
在接口中GenericHttpMessageConverter<T>
- 参数:
type
- the (potentially generic) type to test for readabilitycontextClass
- a context class for the target type, for example a class in which the target type appears in a method signature (can benull
)mediaType
- the media type to read, can benull
if not specified. Typically the value of aContent-Type
header.- 返回:
true
if readable;false
otherwise
canWrite
public boolean canWrite(@Nullable Type type, Class<?> clazz, @Nullable MediaType mediaType)
从接口复制的说明:GenericHttpMessageConverter
Indicates whether the given class can be written by this converter.This method should perform the same checks than
HttpMessageConverter.canWrite(Class, MediaType)
with additional ones related to the generic type.- 指定者:
canWrite
在接口中GenericHttpMessageConverter<T>
- 参数:
type
- the (potentially generic) type to test for writability (can benull
if not specified)clazz
- the source object 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
write
public final void write(T t, @Nullable Type type, @Nullable MediaType contentType, HttpOutputMessage outputMessage) throws IOException, HttpMessageNotWritableException
This implementation sets the default headers by callingAbstractHttpMessageConverter.addDefaultHeaders(org.springframework.http.HttpHeaders, T, org.springframework.http.MediaType)
, and then callswriteInternal(T, org.springframework.http.HttpOutputMessage)
.- 指定者:
write
在接口中GenericHttpMessageConverter<T>
- 参数:
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
.type
- the (potentially generic) type of object to write. This type must have previously been passed to thecanWrite
method of this interface, which must have returnedtrue
. Can benull
if not specified.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
writeInternal
protected void writeInternal(T t, HttpOutputMessage outputMessage) throws IOException, HttpMessageNotWritableException
从类复制的说明:AbstractHttpMessageConverter
Abstract template method that writes the actual body. Invoked fromAbstractHttpMessageConverter.write(T, org.springframework.http.MediaType, org.springframework.http.HttpOutputMessage)
.- 指定者:
writeInternal
在类中AbstractHttpMessageConverter<T>
- 参数:
t
- the object to write to the output messageoutputMessage
- the HTTP output message to write to- 抛出:
IOException
- in case of I/O errorsHttpMessageNotWritableException
- in case of conversion errors
writeInternal
protected abstract void writeInternal(T t, @Nullable Type type, HttpOutputMessage outputMessage) throws IOException, HttpMessageNotWritableException
Abstract template method that writes the actual body. Invoked fromwrite(T, java.lang.reflect.Type, org.springframework.http.MediaType, org.springframework.http.HttpOutputMessage)
.- 参数:
t
- the object to write to the output messagetype
- the type of object to write (may benull
)outputMessage
- the HTTP output message to write to- 抛出:
IOException
- in case of I/O errorsHttpMessageNotWritableException
- in case of conversion errors