public class ObjectToStringHttpMessageConverter extends AbstractHttpMessageConverter<Object>
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>
 logger| Constructor and Description | 
|---|
| ObjectToStringHttpMessageConverter(ConversionService conversionService)A constructor accepting a  ConversionServiceto use to convert the
 (String) message body to/from the target class type. | 
| ObjectToStringHttpMessageConverter(ConversionService conversionService,
                                  Charset defaultCharset)A constructor accepting a  ConversionServiceas well as a default charset. | 
| Modifier and Type | Method and Description | 
|---|---|
| boolean | canRead(Class<?> clazz,
       MediaType mediaType)This implementation checks if the given class is supported,
 and if the supported media types
 include the given media type. | 
| boolean | canWrite(Class<?> clazz,
        MediaType mediaType) | 
| protected Long | getContentLength(Object obj,
                MediaType contentType)Returns the content length for the given type. | 
| protected Object | readInternal(Class<?> clazz,
            HttpInputMessage inputMessage)Abstract template method that reads the actual object. | 
| void | setWriteAcceptCharset(boolean writeAcceptCharset) | 
| protected boolean | supports(Class<?> clazz)Indicates whether the given class is supported by this converter. | 
| protected void | writeInternal(Object obj,
             HttpOutputMessage outputMessage)Abstract template method that writes the actual body. | 
addDefaultHeaders, canRead, canWrite, getDefaultCharset, getDefaultContentType, getSupportedMediaTypes, read, setDefaultCharset, setSupportedMediaTypes, writeclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitgetSupportedMediaTypespublic ObjectToStringHttpMessageConverter(ConversionService conversionService)
ConversionService to use to convert the
 (String) message body to/from the target class type. This constructor uses
 StringHttpMessageConverter.DEFAULT_CHARSET as the default charset.conversionService - the conversion servicepublic ObjectToStringHttpMessageConverter(ConversionService conversionService, Charset defaultCharset)
ConversionService as well as a default charset.conversionService - the conversion servicedefaultCharset - the default charsetpublic void setWriteAcceptCharset(boolean writeAcceptCharset)
public boolean canRead(Class<?> clazz, @Nullable MediaType mediaType)
AbstractHttpMessageConvertercanRead in interface HttpMessageConverter<Object>canRead in class AbstractHttpMessageConverter<Object>clazz - the class to test for readabilitymediaType - 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(Class<?> clazz, @Nullable MediaType mediaType)
AbstractHttpMessageConvertercanWrite in interface HttpMessageConverter<Object>canWrite in class AbstractHttpMessageConverter<Object>clazz - the 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 otherwiseprotected boolean supports(Class<?> clazz)
AbstractHttpMessageConvertersupports in class AbstractHttpMessageConverter<Object>clazz - the class to test for supporttrue if supported; false otherwiseprotected Object readInternal(Class<?> clazz, HttpInputMessage inputMessage) throws IOException, HttpMessageNotReadableException
AbstractHttpMessageConverterAbstractHttpMessageConverter.read(java.lang.Class<? extends T>, org.springframework.http.HttpInputMessage).readInternal in class AbstractHttpMessageConverter<Object>clazz - the type of object to returninputMessage - the HTTP input message to read fromIOException - in case of I/O errorsHttpMessageNotReadableException - in case of conversion errorsprotected void writeInternal(Object obj, HttpOutputMessage outputMessage) throws IOException
AbstractHttpMessageConverterAbstractHttpMessageConverter.write(T, org.springframework.http.MediaType, org.springframework.http.HttpOutputMessage).writeInternal in class AbstractHttpMessageConverter<Object>obj - the object to write to the output messageoutputMessage - the HTTP output message to write toIOException - in case of I/O errorsprotected Long getContentLength(Object obj, @Nullable MediaType contentType)
AbstractHttpMessageConverterBy default, this returns null, meaning that the content length is unknown.
 Can be overridden in subclasses.
getContentLength in class AbstractHttpMessageConverter<Object>obj - the type to return the content length fornull if not known