java.lang.Object | |
↳ | org.springframework.http.converter.AbstractHttpMessageConverter<T> |
Known Direct Subclasses |
Known Indirect Subclasses |
Abstract base class for most HttpMessageConverter
implementations.
This base class adds support for setting supported MediaTypes
, through the
supportedMediaTypes
bean property. It also adds
support for Content-Type
and Content-Length
when writing to output messages.
Fields | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
logger | Logger available to subclasses |
Protected Constructors | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Construct an
AbstractHttpMessageConverter with no supported media types. | |||||||||||
Construct an
AbstractHttpMessageConverter with one supported media type. | |||||||||||
Construct an
AbstractHttpMessageConverter with multiple supported media type. |
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Indicates whether the given class can be read by this converter.
This implementation checks if the given class is | |||||||||||
Indicates whether the given class can be written by this converter.
This implementation checks if the given class is | |||||||||||
Return the list of
MediaType objects supported by this converter. | |||||||||||
Read an object of the given type form the given input message, and returns it.
This implementation simple delegates to | |||||||||||
Set the list of
MediaType objects supported by this converter. | |||||||||||
Write an given object to the given output message.
This implementation delegates to |
Protected Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Returns true if any of the
supported media types
include the given media type. | |||||||||||
Returns true if the given media type includes any of the
supported media types . | |||||||||||
Returns the content length for the given type.
| |||||||||||
Returns the default content type for the given type.
| |||||||||||
Abstract template method that reads the actualy object.
| |||||||||||
Indicates whether the given class is supported by this converter.
| |||||||||||
Abstract template method that writes the actual body.
|
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class
java.lang.Object
| |||||||||||
From interface
org.springframework.http.converter.HttpMessageConverter
|
Logger available to subclasses
Construct an AbstractHttpMessageConverter
with no supported media types.
Construct an AbstractHttpMessageConverter
with one supported media type.
supportedMediaType | the supported media type |
---|
Construct an AbstractHttpMessageConverter
with multiple supported media type.
supportedMediaTypes | the supported media types |
---|
Indicates whether the given class can be read by this converter.
This implementation checks if the given class is supported
,
and if the supported media types
include
the given media type.
clazz | the class to test for readability |
---|---|
mediaType | the media type to read, can be null if not specified.
Typically the value of a Content-Type header. |
true
if readable; false
otherwise
Indicates whether the given class can be written by this converter.
This implementation checks if the given class is supported
,
and if the supported media types
include
the given media type.
clazz | the class to test for writability |
---|---|
mediaType | the media type to write, can be null if not specified.
Typically the value of an Accept header. |
true
if writable; false
otherwise
Return the list of MediaType
objects supported by this converter.
Read an object of the given type form the given input message, and returns it.
This implementation simple delegates to readInternal(Class, HttpInputMessage)
.
Future implementations might add some default behavior, however.
clazz | the type of object to return. This type must have previously been passed to the
canRead method of this interface, which must have returned true . |
---|---|
inputMessage | the HTTP input message to read from |
IOException |
---|
Set the list of MediaType
objects supported by this converter.
Write an given object to the given output message.
This implementation delegates to getDefaultContentType(Object)
if a content
type was not provided, calls getContentLength(T, MediaType)
, and sets the corresponding headers
on the output message. It then calls writeInternal(T, HttpOutputMessage)
.
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 . |
---|---|
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 to |
Returns true if any of the supported media types
include the given media type.
mediaType | the media type to read, can be null if not specified. Typically the value of a
Content-Type header. |
---|
null
Returns true if the given media type includes any of the
supported media types
.
mediaType | the media type to write, can be null if not specified. Typically the value of an
Accept header. |
---|
null
Returns the content length for the given type.
By default, this returns null
, meaning that the content length is unknown.
Can be overridden in subclasses.
t | the type to return the content length for |
---|
null
if not known
Returns the default content type for the given type. Called when write(T, MediaType, HttpOutputMessage)
is invoked without a specified content type parameter.
By default, this returns the first element of the
supportedMediaTypes
property, if any.
Can be overridden in subclasses.
t | the type to return the content type for |
---|
null
if not known
Abstract template method that reads the actualy object. Invoked from read(Class extends T>, HttpInputMessage)
.
clazz | the type of object to return |
---|---|
inputMessage | the HTTP input message to read from |
IOException | in case of I/O errors |
---|---|
HttpMessageNotReadableException | in case of conversion errors |
Indicates whether the given class is supported by this converter.
clazz | the class to test for support |
---|
true
if supported; false
otherwise
Abstract template method that writes the actual body. Invoked from write(T, MediaType, HttpOutputMessage)
.
t | the object to write to the output message |
---|---|
outputMessage | the message to write to |
IOException | in case of I/O errors |
---|---|
HttpMessageNotWritableException | in case of conversion errors |