类 ObjectToStringHttpMessageConverter
java.lang.Object
cn.taketoday.http.converter.AbstractHttpMessageConverter<Object>
cn.taketoday.http.converter.ObjectToStringHttpMessageConverter
- 所有已实现的接口:
HttpMessageConverter<Object>
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="cn.taketoday.http.converter.ObjectToStringHttpMessageConverter">
<constructor-arg>
<bean class="cn.taketoday.context.support.ConversionServiceFactoryBean"/>
</constructor-arg>
</bean>
- 从以下版本开始:
- 4.0
- 作者:
- Dmitry Katsubo, Rossen Stoyanchev
-
字段概要
字段修饰符和类型字段说明private final cn.taketoday.core.conversion.ConversionServiceprivate final StringHttpMessageConverter从类继承的字段 cn.taketoday.http.converter.AbstractHttpMessageConverter
logger -
构造器概要
构造器构造器说明ObjectToStringHttpMessageConverter(cn.taketoday.core.conversion.ConversionService conversionService) A constructor accepting aConversionServiceto use to convert the (String) message body to/from the target class type.ObjectToStringHttpMessageConverter(cn.taketoday.core.conversion.ConversionService conversionService, Charset defaultCharset) A constructor accepting aConversionServiceas well as a default charset. -
方法概要
修饰符和类型方法说明booleanThis implementation checks if the given class is supported, and if the supported media types include the given media type.booleanprotected 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 booleanIndicates whether the given class is supported by this converter.protected voidwriteInternal(Object obj, HttpOutputMessage outputMessage) Abstract template method that writes the actual body.从类继承的方法 cn.taketoday.http.converter.AbstractHttpMessageConverter
addDefaultHeaders, canRead, canWrite, getDefaultCharset, getDefaultContentType, getSupportedMediaTypes, read, setDefaultCharset, setSupportedMediaTypes, write从类继承的方法 java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait从接口继承的方法 cn.taketoday.http.converter.HttpMessageConverter
getSupportedMediaTypes
-
字段详细资料
-
conversionService
private final cn.taketoday.core.conversion.ConversionService conversionService -
stringHttpMessageConverter
-
-
构造器详细资料
-
ObjectToStringHttpMessageConverter
public ObjectToStringHttpMessageConverter(cn.taketoday.core.conversion.ConversionService conversionService) A constructor accepting aConversionServiceto use to convert the (String) message body to/from the target class type. This constructor usesConstant.DEFAULT_CHARSETas the default charset.- 参数:
conversionService- the conversion service
-
ObjectToStringHttpMessageConverter
public ObjectToStringHttpMessageConverter(cn.taketoday.core.conversion.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
从类复制的说明:AbstractHttpMessageConverterThis implementation checks if the given class is supported, and if the supported media types include 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
从类复制的说明: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
从类复制的说明: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>, cn.taketoday.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
从类复制的说明:AbstractHttpMessageConverterAbstract template method that writes the actual body. Invoked fromAbstractHttpMessageConverter.write(T, cn.taketoday.http.MediaType, cn.taketoday.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
从类复制的说明: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
-