spring-framework / org.springframework.http.converter / ObjectToStringHttpMessageConverter

ObjectToStringHttpMessageConverter

open class ObjectToStringHttpMessageConverter : AbstractHttpMessageConverter<Any>

An 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> 

Author
Dmitry Katsubo

Author
Rossen Stoyanchev

Since
3.2

Constructors

<init>

ObjectToStringHttpMessageConverter(conversionService: ConversionService)

A constructor accepting a 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.

ObjectToStringHttpMessageConverter(conversionService: ConversionService, defaultCharset: Charset)

A constructor accepting a ConversionService as well as a default charset.

Functions

canRead

open fun canRead(clazz: Class<*>, mediaType: MediaType): Boolean

canWrite

open fun canWrite(clazz: Class<*>, mediaType: MediaType): Boolean

setWriteAcceptCharset

open fun setWriteAcceptCharset(writeAcceptCharset: Boolean): Unit

Indicates whether the Accept-Charset should be written to any outgoing request.

Default is true.