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.
| Modifier and Type | Field and Description |
|---|---|
| private Charset | |
| protected final Log | logger
Logger available to subclasses. |
| private List |
| Access | Constructor and Description |
|---|---|
| protected | AbstractHttpMessageConverter()
Construct an |
| protected | AbstractHttpMessageConverter(MediaType
the supported media type supportedMediaType)Construct an |
| protected | AbstractHttpMessageConverter(MediaType...
the supported media types supportedMediaTypes)Construct an |
| protected | AbstractHttpMessageConverter(Charset
the default character set defaultCharset, MediaType... the supported media types supportedMediaTypes)Construct an |
| Modifier and Type | Method and Description |
|---|---|
| protected void | addDefaultHeaders(HttpHeaders headers, T t, MediaType contentType)
Add default headers to the output message. |
| public boolean | canRead(Class<?>
the class to test for readability clazz, MediaType the media type to read (can be mediaType)null if not specified);
typically the value of a Content-Type header.Implements org. This implementation checks if the given class is supported, and if the supported media types include the given media type. |
| protected boolean | Returns: true if the supported media types include the media type,
or if the media type is nullthe media type to read, can be mediaType)null if not specified.
Typically the value of a Content-Type header.Returns |
| public boolean | canWrite(Class<?>
the class to test for writability clazz, MediaType the media type to write (can be mediaType)null if not specified);
typically the value of an Accept header.Implements org. This implementation checks if the given class is supported, and if the supported media types include the given media type. |
| protected boolean | Returns: true if the supported media types are compatible with the media type,
or if the media type is nullthe media type to write, can be mediaType)null if not specified.
Typically the value of an Accept header.Returns |
| protected Long | Returns: the content length, ornull if not knownthe type to return the content length for t, MediaType contentType)Returns the content length for the given type. |
| public Charset | |
| protected MediaType | Returns: the content type, ornull if not knownthe type to return the content type for t)Returns the default content type for the given type. |
| public List | getSupportedMediaTypes()
Implements org. Return the list of media types supported by this converter. |
| public final T | read(Class<? extends T>
the type of object to return. This type must have previously been passed to the
clazz, HttpInputMessage canRead method of this interface, which must have returned true.the HTTP input message to read from inputMessage)Implements org. This implementation simple delegates to |
| protected abstract T | Returns: the converted objectthe type of object to return clazz, HttpInputMessage the HTTP input message to read from inputMessage)Abstract template method that reads the actual object. |
| public void | |
| public void | setSupportedMediaTypes(List<MediaType> supportedMediaTypes)
Set the list of |
| protected abstract boolean | |
| protected boolean | Returns: true if t can be written repeatedly;
false otherwisethe object t t)Indicates whether this message converter can write the given object multiple times. |
| public final void | write(final T
the object to write to the output message. The type of this object must have previously been
passed to the t, MediaType canWrite method of this interface, which must have returned true.the content type to use when writing. May be contentType, HttpOutputMessage 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.the message to write to outputMessage)Implements org. This implementation sets the default headers by calling |
| protected abstract void | writeInternal(T
the object to write to the output message t, HttpOutputMessage the HTTP output message to write to outputMessage)Abstract template method that writes the actual body. |
| defaultCharset | back to summary |
|---|---|
| private Charset defaultCharset
| |
| logger | back to summary |
|---|---|
| protected final Log logger Logger available to subclasses. | |
| supportedMediaTypes | back to summary |
|---|---|
| private List<MediaType> supportedMediaTypes | |
| AbstractHttpMessageConverter | back to summary |
|---|---|
| protected AbstractHttpMessageConverter() Construct an
| |
| AbstractHttpMessageConverter | back to summary |
|---|---|
| protected AbstractHttpMessageConverter(MediaType supportedMediaType) Construct an
| |
| AbstractHttpMessageConverter | back to summary |
|---|---|
| protected AbstractHttpMessageConverter(MediaType... supportedMediaTypes) Construct an
| |
| AbstractHttpMessageConverter | back to summary |
|---|---|
| protected AbstractHttpMessageConverter(Charset defaultCharset, MediaType... supportedMediaTypes) Construct an | |
| addDefaultHeaders | back to summary |
|---|---|
| protected void addDefaultHeaders(HttpHeaders headers, T t, MediaType contentType) throws IOException Add default headers to the output message. This implementation delegates to
| |
| canRead | back to summary |
|---|---|
| public boolean canRead(Class<?> clazz, MediaType mediaType) Implements org. This implementation checks if the given class is supported, and if the supported media types include the given media type.
| |
| canRead | back to summary |
|---|---|
| protected boolean canRead(MediaType mediaType) Returns
| |
| canWrite | back to summary |
|---|---|
| public boolean canWrite(Class<?> clazz, MediaType mediaType) Implements org. This implementation checks if the given class is supported, and if the supported media types include the given media type.
| |
| canWrite | back to summary |
|---|---|
| protected boolean canWrite(MediaType mediaType) Returns
| |
| getContentLength | back to summary |
|---|---|
| protected Long getContentLength(T t, MediaType contentType) throws IOException Returns the content length for the given type. By default, this returns | |
| getDefaultCharset | back to summary |
|---|---|
| public Charset getDefaultCharset() Return the default character set, if any.
| |
| getDefaultContentType | back to summary |
|---|---|
| protected MediaType getDefaultContentType(T t) throws IOException Returns the default content type for the given type. Called when By default, this returns the first element of the
| |
| getSupportedMediaTypes | back to summary |
|---|---|
| public List Implements org. Doc from org. Return the list of media types supported by this converter. The list may
not apply to every possible target element type and calls to this method
should typically be guarded via | |
| read | back to summary |
|---|---|
| public final T read(Class<? extends T> clazz, HttpInputMessage inputMessage) throws IOException, HttpMessageNotReadableException Implements org. This implementation simple delegates to
| |
| readInternal | back to summary |
|---|---|
| protected abstract T readInternal(Class<? extends T> clazz, HttpInputMessage inputMessage) throws IOException, HttpMessageNotReadableException Abstract template method that reads the actual object. Invoked from
| |
| setDefaultCharset | back to summary |
|---|---|
| public void setDefaultCharset(Charset defaultCharset) Set the default character set, if any.
| |
| setSupportedMediaTypes | back to summary |
|---|---|
| public void setSupportedMediaTypes(List<MediaType> supportedMediaTypes) Set the list of | |
| supports | back to summary |
|---|---|
| protected abstract boolean supports(Class<?> clazz) Indicates whether the given class is supported by this converter.
| |
| supportsRepeatableWrites | back to summary |
|---|---|
| protected boolean supportsRepeatableWrites(T t) Indicates whether this message converter can write the given object multiple times. Default implementation returns
| |
| write | back to summary |
|---|---|
| public final void write(final T t, MediaType contentType, HttpOutputMessage outputMessage) throws IOException, HttpMessageNotWritableException Implements org. This implementation sets the default headers by calling
| |
| writeInternal | back to summary |
|---|---|
| protected abstract void writeInternal(T t, HttpOutputMessage outputMessage) throws IOException, HttpMessageNotWritableException Abstract template method that writes the actual body. Invoked from
| |