HttpMessageConverter that uses StringHttpMessageConverter
for reading and writing content and a ConversionService for converting
the String content to and from the target object type.
By default, this converter supports the media type text/plain only.
This can be overridden through the supportedMediaTypes
property.
A usage example:
<bean class="org.springframework.http.converter.ObjectToStringHttpMessageConverter">
<constructor-arg>
<bean class="org.springframework.context.support.ConversionServiceFactoryBean"/>
</constructor-arg>
</bean>
| Modifier and Type | Field and Description |
|---|---|
| private final ConversionService | |
| private final StringHttpMessageConverter |
| Access | Constructor and Description |
|---|---|
| public | ObjectToStringHttpMessageConverter(ConversionService
the conversion service conversionService)A constructor accepting a |
| public | ObjectToStringHttpMessageConverter(ConversionService
the conversion service conversionService, Charset the default charset defaultCharset)A constructor accepting a |
| Modifier and Type | Method and Description |
|---|---|
| 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.Overrides org. Implements org. |
| 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.Overrides org. Implements org. |
| protected Long | getContentLength(Object
the type to return the content length for obj, MediaType contentType)Overrides org. |
| protected Object | readInternal(Class<?>
the type of object to return clazz, HttpInputMessage the HTTP input message to read from inputMessage)Implements abstract org. |
| public void | setWriteAcceptCharset(boolean writeAcceptCharset)
Delegates to |
| protected boolean | supports(Class<?>
the class to test for support clazz)Implements abstract org. |
| protected boolean | supportsRepeatableWrites(Object
the object t o)Overrides org. |
| protected void | writeInternal(Object
the object to write to the output message obj, HttpOutputMessage the HTTP output message to write to outputMessage)Implements abstract org. |
| conversionService | back to summary |
|---|---|
| private final ConversionService conversionService | |
| stringHttpMessageConverter | back to summary |
|---|---|
| private final StringHttpMessageConverter stringHttpMessageConverter | |
| ObjectToStringHttpMessageConverter | back to summary |
|---|---|
| public ObjectToStringHttpMessageConverter(ConversionService conversionService) A constructor accepting a
| |
| ObjectToStringHttpMessageConverter | back to summary |
|---|---|
| public ObjectToStringHttpMessageConverter(ConversionService conversionService, Charset defaultCharset) A constructor accepting a
| |
| canRead | back to summary |
|---|---|
| public boolean canRead(Class<?> clazz, MediaType mediaType) Overrides org. Implements org. Doc from 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 |
|---|---|
| public boolean canWrite(Class<?> clazz, MediaType mediaType) Overrides org. Implements org. Doc from org. This implementation checks if the given class is supported, and if the supported media types include the given media type.
| |
| getContentLength | back to summary |
|---|---|
| protected Long getContentLength(Object obj, MediaType contentType) Overrides org. Doc from org. Returns the content length for the given type. By default, this returns | |
| readInternal | back to summary |
|---|---|
| protected Object readInternal(Class<?> clazz, HttpInputMessage inputMessage) throws IOException, HttpMessageNotReadableException Implements abstract org. Doc from org. Abstract template method that reads the actual object. Invoked from
| |
| setWriteAcceptCharset | back to summary |
|---|---|
| public void setWriteAcceptCharset(boolean writeAcceptCharset) Delegates to | |
| supports | back to summary |
|---|---|
| protected boolean supports(Class<?> clazz) Implements abstract org. Doc from org. Indicates whether the given class is supported by this converter. | |
| supportsRepeatableWrites | back to summary |
|---|---|
| protected boolean supportsRepeatableWrites(Object o) Overrides org. Doc from org. Indicates whether this message converter can write the given object multiple times. Default implementation returns | |
| writeInternal | back to summary |
|---|---|
| protected void writeInternal(Object obj, HttpOutputMessage outputMessage) throws IOException Implements abstract org. Doc from org. Abstract template method that writes the actual body. Invoked from
| |