类 AbstractJsonHttpMessageConverter
- java.lang.Object
- org.springframework.http.converter.AbstractHttpMessageConverter<T>
- org.springframework.http.converter.AbstractGenericHttpMessageConverter<Object>
- org.springframework.http.converter.json.AbstractJsonHttpMessageConverter
- 所有已实现的接口:
GenericHttpMessageConverter<Object>,HttpMessageConverter<Object>
public abstract class AbstractJsonHttpMessageConverter extends AbstractGenericHttpMessageConverter<Object>
Common base class for plain JSON converters, e.g. Gson and JSON-B.Note that the Jackson converters have a dedicated class hierarchy due to their multi-format support.
- 从以下版本开始:
- 5.0
- 作者:
- Juergen Hoeller
- 另请参阅:
GsonHttpMessageConverter,JsonbHttpMessageConverter,readInternal(Type, Reader),writeInternal(Object, Type, Writer)
字段概要
字段 修饰符和类型 字段 说明 static CharsetDEFAULT_CHARSETThe default charset used by the converter.从类继承的字段 org.springframework.http.converter.AbstractHttpMessageConverter
logger
构造器概要
构造器 构造器 说明 AbstractJsonHttpMessageConverter()
方法概要
所有方法 实例方法 抽象方法 具体方法 修饰符和类型 方法 说明 Objectread(Type type, Class<?> contextClass, HttpInputMessage inputMessage)Read an object of the given type form the given input message, and returns it.protected ObjectreadInternal(Class<?> clazz, HttpInputMessage inputMessage)Abstract template method that reads the actual object.protected abstract ObjectreadInternal(Type resolvedType, Reader reader)Template method that reads the JSON-bound object from the givenReader.voidsetJsonPrefix(String jsonPrefix)Specify a custom prefix to use for JSON output.voidsetPrefixJson(boolean prefixJson)Indicate whether the JSON output by this view should be prefixed with ")]}', ".protected abstract voidwriteInternal(Object object, Type type, Writer writer)Template method that writes the JSON-bound object to the givenWriter.protected voidwriteInternal(Object object, Type type, HttpOutputMessage outputMessage)Abstract template method that writes the actual body.从类继承的方法 org.springframework.http.converter.AbstractGenericHttpMessageConverter
canRead, canWrite, supports, write, writeInternal
从类继承的方法 org.springframework.http.converter.AbstractHttpMessageConverter
addDefaultHeaders, canRead, canRead, canWrite, canWrite, getContentLength, getDefaultCharset, getDefaultContentType, getSupportedMediaTypes, read, setDefaultCharset, setSupportedMediaTypes, write
从类继承的方法 java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
从接口继承的方法 org.springframework.http.converter.HttpMessageConverter
canRead, canWrite, getSupportedMediaTypes, read, write
字段详细资料
DEFAULT_CHARSET
public static final Charset DEFAULT_CHARSET
The default charset used by the converter.
构造器详细资料
AbstractJsonHttpMessageConverter
public AbstractJsonHttpMessageConverter()
方法详细资料
setJsonPrefix
public void setJsonPrefix(String jsonPrefix)
Specify a custom prefix to use for JSON output. Default is none.
setPrefixJson
public void setPrefixJson(boolean prefixJson)
Indicate whether the JSON output by this view should be prefixed with ")]}', ". Default isfalse.Prefixing the JSON string in this manner is used to help prevent JSON Hijacking. The prefix renders the string syntactically invalid as a script so that it cannot be hijacked. This prefix should be stripped before parsing the string as JSON.
read
public final Object read(Type type, @Nullable Class<?> contextClass, HttpInputMessage inputMessage) throws IOException, HttpMessageNotReadableException
从接口复制的说明:GenericHttpMessageConverterRead an object of the given type form the given input message, and returns it.- 参数:
type- the (potentially generic) type of object to return. This type must have previously been passed to thecanReadmethod of this interface, which must have returnedtrue.contextClass- a context class for the target type, for example a class in which the target type appears in a method signature (can benull)inputMessage- the HTTP input message to read from- 返回:
- the converted object
- 抛出:
IOException- in case of I/O errorsHttpMessageNotReadableException- in case of conversion errors
readInternal
protected final 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 final void writeInternal(Object object, @Nullable Type type, HttpOutputMessage outputMessage) throws IOException, HttpMessageNotWritableException
从类复制的说明:AbstractGenericHttpMessageConverterAbstract template method that writes the actual body. Invoked fromAbstractGenericHttpMessageConverter.write(T, java.lang.reflect.Type, org.springframework.http.MediaType, org.springframework.http.HttpOutputMessage).- 指定者:
writeInternal在类中AbstractGenericHttpMessageConverter<Object>- 参数:
object- the object to write to the output messagetype- the type of object to write (may benull)outputMessage- the HTTP output message to write to- 抛出:
IOException- in case of I/O errorsHttpMessageNotWritableException- in case of conversion errors
readInternal
protected abstract Object readInternal(Type resolvedType, Reader reader) throws Exception
Template method that reads the JSON-bound object from the givenReader.- 参数:
resolvedType- the resolved generic typereader- the Reader to use- 返回:
- the JSON-bound object
- 抛出:
Exception- in case of read/parse failures
writeInternal
protected abstract void writeInternal(Object object, @Nullable Type type, Writer writer) throws Exception
Template method that writes the JSON-bound object to the givenWriter.- 参数:
object- the object to write to the output messagetype- the type of object to write (may benull)writer- the Writer to use- 抛出:
Exception- in case of write failures