类 ObjectToStringHttpMessageConverter
- java.lang.Object
- org.springframework.http.converter.AbstractHttpMessageConverter<Object>
- org.springframework.http.converter.ObjectToStringHttpMessageConverter
- 所有已实现的接口:
HttpMessageConverter<Object>
public class ObjectToStringHttpMessageConverter extends AbstractHttpMessageConverter<Object>
AnHttpMessageConverter
that usesStringHttpMessageConverter
for reading and writing content and aConversionService
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 thesupportedMediaTypes
property.A usage example:
<bean class="org.springframework.http.converter.ObjectToStringHttpMessageConverter"> <constructor-arg> <bean class="org.springframework.context.support.ConversionServiceFactoryBean"/> </constructor-arg> </bean>
- 从以下版本开始:
- 3.2
- 作者:
- Dmitry Katsubo, Rossen Stoyanchev
字段概要
从类继承的字段 org.springframework.http.converter.AbstractHttpMessageConverter
logger
构造器概要
构造器 构造器 说明 ObjectToStringHttpMessageConverter(ConversionService conversionService)
A constructor accepting aConversionService
to use to convert the (String) message body to/from the target class type.ObjectToStringHttpMessageConverter(ConversionService conversionService, Charset defaultCharset)
A constructor accepting aConversionService
as well as a default charset.
方法概要
所有方法 实例方法 具体方法 修饰符和类型 方法 说明 boolean
canRead(Class<?> clazz, MediaType mediaType)
This implementation checks if the given class is supported, and if the supported media typesinclude 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)
Indicates whether theAccept-Charset
should be written to any outgoing request.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.从类继承的方法 org.springframework.http.converter.AbstractHttpMessageConverter
addDefaultHeaders, canRead, canWrite, getDefaultCharset, getDefaultContentType, getSupportedMediaTypes, read, setDefaultCharset, setSupportedMediaTypes, write
构造器详细资料
ObjectToStringHttpMessageConverter
public ObjectToStringHttpMessageConverter(ConversionService conversionService)
A constructor accepting aConversionService
to use to convert the (String) message body to/from the target class type. This constructor usesStringHttpMessageConverter.DEFAULT_CHARSET
as the default charset.- 参数:
conversionService
- the conversion service
ObjectToStringHttpMessageConverter
public ObjectToStringHttpMessageConverter(ConversionService conversionService, Charset defaultCharset)
A constructor accepting aConversionService
as well as a default charset.- 参数:
conversionService
- the conversion servicedefaultCharset
- the default charset
方法详细资料
setWriteAcceptCharset
public void setWriteAcceptCharset(boolean writeAcceptCharset)
Indicates whether theAccept-Charset
should be written to any outgoing request.Default is
true
.
canRead
public boolean canRead(Class<?> clazz, MediaType mediaType)
从类复制的说明:AbstractHttpMessageConverter
This implementation checks if the given class is supported, and if the supported media typesinclude the given media type.- 指定者:
canRead
在接口中HttpMessageConverter<Object>
- 覆盖:
canRead
在类中AbstractHttpMessageConverter<Object>
- 参数:
clazz
- the class to test for readabilitymediaType
- the media type to read (can benull
if not specified); typically the value of aContent-Type
header.- 返回:
true
if readable;false
otherwise
canWrite
public boolean canWrite(Class<?> clazz, MediaType mediaType)
从类复制的说明:AbstractHttpMessageConverter
This implementation checks if the given class is supported, and if the supported media types include the given media type.- 指定者:
canWrite
在接口中HttpMessageConverter<Object>
- 覆盖:
canWrite
在类中AbstractHttpMessageConverter<Object>
- 参数:
clazz
- the class to test for writabilitymediaType
- the media type to write (can benull
if not specified); typically the value of anAccept
header.- 返回:
true
if writable;false
otherwise
supports
protected boolean supports(Class<?> clazz)
从类复制的说明:AbstractHttpMessageConverter
Indicates whether the given class is supported by this converter.- 指定者:
supports
在类中AbstractHttpMessageConverter<Object>
- 参数:
clazz
- the class to test for support- 返回:
true
if supported;false
otherwise
readInternal
protected Object readInternal(Class<?> clazz, HttpInputMessage inputMessage) throws IOException
从类复制的说明:AbstractHttpMessageConverter
Abstract template method that reads the actual object. Invoked fromAbstractHttpMessageConverter.read(java.lang.Class<? extends T>, org.springframework.http.HttpInputMessage)
.- 指定者:
readInternal
在类中AbstractHttpMessageConverter<Object>
- 参数:
clazz
- the type of object to returninputMessage
- the HTTP input message to read from- 返回:
- the converted object
- 抛出:
IOException
- in case of I/O errors
writeInternal
protected void writeInternal(Object obj, HttpOutputMessage outputMessage) throws IOException
从类复制的说明:AbstractHttpMessageConverter
Abstract template method that writes the actual body. Invoked fromAbstractHttpMessageConverter.write(T, org.springframework.http.MediaType, org.springframework.http.HttpOutputMessage)
.- 指定者:
writeInternal
在类中AbstractHttpMessageConverter<Object>
- 参数:
obj
- the object to write to the output messageoutputMessage
- the HTTP output message to write to- 抛出:
IOException
- in case of I/O errors
getContentLength
protected Long getContentLength(Object obj, MediaType contentType)
从类复制的说明:AbstractHttpMessageConverter
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.- 覆盖:
getContentLength
在类中AbstractHttpMessageConverter<Object>
- 参数:
obj
- the type to return the content length for- 返回:
- the content length, or
null
if not known