T
- the converted object typepublic abstract class AbstractGenericHttpMessageConverter<T> extends AbstractHttpMessageConverter<T> implements GenericHttpMessageConverter<T>
GenericHttpMessageConverter
implementations.logger
Modifier | Constructor and Description |
---|---|
protected |
AbstractGenericHttpMessageConverter()
Construct an
AbstractGenericHttpMessageConverter with no supported media types. |
protected |
AbstractGenericHttpMessageConverter(MediaType... supportedMediaTypes)
Construct an
AbstractGenericHttpMessageConverter with multiple supported media type. |
protected |
AbstractGenericHttpMessageConverter(MediaType supportedMediaType)
Construct an
AbstractGenericHttpMessageConverter with one supported media type. |
Modifier and Type | Method and Description |
---|---|
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 calling
AbstractHttpMessageConverter.addDefaultHeaders(org.springframework.http.HttpHeaders, T, org.springframework.http.MediaType) ,
and then calls writeInternal(T, org.springframework.http.HttpOutputMessage) . |
protected void |
writeInternal(T t,
HttpOutputMessage outputMessage)
Abstract template method that writes the actual body.
|
protected abstract void |
writeInternal(T t,
Type type,
HttpOutputMessage outputMessage)
Abstract template method that writes the actual body.
|
addDefaultHeaders, canRead, canRead, canWrite, canWrite, getContentLength, getDefaultCharset, getDefaultContentType, getSupportedMediaTypes, read, readInternal, setDefaultCharset, setSupportedMediaTypes, write
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
read
canRead, canWrite, getSupportedMediaTypes, getSupportedMediaTypes, read, write
protected AbstractGenericHttpMessageConverter()
AbstractGenericHttpMessageConverter
with no supported media types.protected AbstractGenericHttpMessageConverter(MediaType supportedMediaType)
AbstractGenericHttpMessageConverter
with one supported media type.supportedMediaType
- the supported media typeprotected AbstractGenericHttpMessageConverter(MediaType... supportedMediaTypes)
AbstractGenericHttpMessageConverter
with multiple supported media type.supportedMediaTypes
- the supported media typesprotected boolean supports(Class<?> clazz)
AbstractHttpMessageConverter
supports
in class AbstractHttpMessageConverter<T>
clazz
- the class to test for supporttrue
if supported; false
otherwisepublic boolean canRead(Type type, @Nullable Class<?> contextClass, @Nullable MediaType mediaType)
GenericHttpMessageConverter
HttpMessageConverter.canRead(Class, MediaType)
with additional ones
related to the generic type.canRead
in interface 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 be null
)mediaType
- the media type to read, can be null
if not specified.
Typically, the value of a Content-Type
header.true
if readable; false
otherwisepublic boolean canWrite(@Nullable Type type, Class<?> clazz, @Nullable MediaType mediaType)
GenericHttpMessageConverter
This method should perform the same checks as
HttpMessageConverter.canWrite(Class, MediaType)
with additional ones
related to the generic type.
canWrite
in interface GenericHttpMessageConverter<T>
type
- the (potentially generic) type to test for writability
(can be null
if not specified)clazz
- the source object class to test for writabilitymediaType
- the media type to write (can be null
if not specified);
typically the value of an Accept
header.true
if writable; false
otherwisepublic final void write(T t, @Nullable Type type, @Nullable MediaType contentType, HttpOutputMessage outputMessage) throws IOException, HttpMessageNotWritableException
AbstractHttpMessageConverter.addDefaultHeaders(org.springframework.http.HttpHeaders, T, org.springframework.http.MediaType)
,
and then calls writeInternal(T, org.springframework.http.HttpOutputMessage)
.write
in interface GenericHttpMessageConverter<T>
t
- the object to write to the output message. The type of this object must
have previously been passed to the canWrite
method of this
interface, which must have returned true
.type
- the (potentially generic) type of object to write. This type must have
previously been passed to the canWrite
method of this interface,
which must have returned true
. Can be null
if not specified.contentType
- the content type to use when writing. May be null
to
indicate that the default content type of the converter must be used. If not
null
, this media type must have previously been passed to the
canWrite
method of this interface, which must have returned
true
.outputMessage
- the message to write toIOException
- in case of I/O errorsHttpMessageNotWritableException
- in case of conversion errorsprotected void writeInternal(T t, HttpOutputMessage outputMessage) throws IOException, HttpMessageNotWritableException
AbstractHttpMessageConverter
AbstractHttpMessageConverter.write(T, org.springframework.http.MediaType, org.springframework.http.HttpOutputMessage)
.writeInternal
in class AbstractHttpMessageConverter<T>
t
- the object to write to the output messageoutputMessage
- the HTTP output message to write toIOException
- in case of I/O errorsHttpMessageNotWritableException
- in case of conversion errorsprotected abstract void writeInternal(T t, @Nullable Type type, HttpOutputMessage outputMessage) throws IOException, HttpMessageNotWritableException
write(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 be null
)outputMessage
- the HTTP output message to write toIOException
- in case of I/O errorsHttpMessageNotWritableException
- in case of conversion errors