类 ObjectToStringHttpMessageConverter
- java.lang.Object
- org.springframework.http.converter.AbstractHttpMessageConverter<Object>
- org.springframework.http.converter.ObjectToStringHttpMessageConverter
- 所有已实现的接口:
HttpMessageConverter<Object>
public class ObjectToStringHttpMessageConverter extends AbstractHttpMessageConverter<Object>
AnHttpMessageConverterthat usesStringHttpMessageConverterfor reading and writing content and aConversionServicefor converting the String content to and from the target object type.By default, this converter supports the media type
text/plainonly. This can be overridden through thesupportedMediaTypesproperty.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 aConversionServiceto use to convert the (String) message body to/from the target class type.ObjectToStringHttpMessageConverter(ConversionService conversionService, Charset defaultCharset)A constructor accepting aConversionServiceas well as a default charset.
方法概要
所有方法 实例方法 具体方法 修饰符和类型 方法 说明 booleancanRead(Class<?> clazz, MediaType mediaType)This implementation checks if the given class is supported, and if the supported media typesinclude the given media type.booleancanWrite(Class<?> clazz, MediaType mediaType)protected LonggetContentLength(Object obj, MediaType contentType)Returns the content length for the given type.protected ObjectreadInternal(Class<?> clazz, HttpInputMessage inputMessage)Abstract template method that reads the actual object.voidsetWriteAcceptCharset(boolean writeAcceptCharset)protected booleansupports(Class<?> clazz)Indicates whether the given class is supported by this converter.protected voidwriteInternal(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 aConversionServiceto use to convert the (String) message body to/from the target class type. This constructor usesStringHttpMessageConverter.DEFAULT_CHARSETas the default charset.- 参数:
conversionService- the conversion service
ObjectToStringHttpMessageConverter
public ObjectToStringHttpMessageConverter(ConversionService conversionService, Charset defaultCharset)
A constructor accepting aConversionServiceas well as a default charset.- 参数:
conversionService- the conversion servicedefaultCharset- the default charset
方法详细资料
setWriteAcceptCharset
public void setWriteAcceptCharset(boolean writeAcceptCharset)
canRead
public boolean canRead(Class<?> clazz, @Nullable MediaType mediaType)
从类复制的说明:AbstractHttpMessageConverterThis 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 benullif not specified); typically the value of aContent-Typeheader.- 返回:
trueif readable;falseotherwise
canWrite
public boolean canWrite(Class<?> clazz, @Nullable MediaType mediaType)
从类复制的说明:AbstractHttpMessageConverterThis 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 benullif not specified); typically the value of anAcceptheader.- 返回:
trueif writable;falseotherwise
supports
protected boolean supports(Class<?> clazz)
从类复制的说明:AbstractHttpMessageConverterIndicates whether the given class is supported by this converter.- 指定者:
supports在类中AbstractHttpMessageConverter<Object>- 参数:
clazz- the class to test for support- 返回:
trueif supported;falseotherwise
readInternal
protected Object readInternal(Class<?> clazz, HttpInputMessage inputMessage) throws IOException, HttpMessageNotReadableException
从类复制的说明:AbstractHttpMessageConverterAbstract 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 errorsHttpMessageNotReadableException- in case of conversion errors
writeInternal
protected void writeInternal(Object obj, HttpOutputMessage outputMessage) throws IOException
从类复制的说明:AbstractHttpMessageConverterAbstract 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, @Nullable MediaType contentType)
从类复制的说明:AbstractHttpMessageConverterReturns 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
nullif not known