public abstract class AbstractJsonHttpMessageConverter extends AbstractGenericHttpMessageConverter<java.lang.Object>
Note that the Jackson converters have a dedicated class hierarchy due to their multi-format support.
GsonHttpMessageConverter
,
JsonbHttpMessageConverter
,
readInternal(Type, Reader)
,
writeInternal(Object, Type, Writer)
Modifier and Type | Field and Description |
---|---|
static java.nio.charset.Charset |
DEFAULT_CHARSET |
logger
Constructor and Description |
---|
AbstractJsonHttpMessageConverter() |
Modifier and Type | Method and Description |
---|---|
java.lang.Object |
read(java.lang.reflect.Type type,
java.lang.Class<?> contextClass,
HttpInputMessage inputMessage)
Read an object of the given type form the given input message, and returns it.
|
protected java.lang.Object |
readInternal(java.lang.Class<?> clazz,
HttpInputMessage inputMessage)
Abstract template method that reads the actual object.
|
protected abstract java.lang.Object |
readInternal(java.lang.reflect.Type resolvedType,
java.io.Reader reader)
Template method that reads the JSON-bound object from the given
Reader . |
void |
setJsonPrefix(java.lang.String jsonPrefix)
Specify a custom prefix to use for JSON output.
|
void |
setPrefixJson(boolean prefixJson)
Indicate whether the JSON output by this view should be prefixed with ")]}', ".
|
protected void |
writeInternal(java.lang.Object o,
java.lang.reflect.Type type,
HttpOutputMessage outputMessage)
Abstract template method that writes the actual body.
|
protected abstract void |
writeInternal(java.lang.Object o,
java.lang.reflect.Type type,
java.io.Writer writer)
Template method that writes the JSON-bound object to the given
Writer . |
canRead, canWrite, supports, write, writeInternal
addDefaultHeaders, canRead, canRead, canWrite, canWrite, getContentLength, getDefaultCharset, getDefaultContentType, getSupportedMediaTypes, read, setDefaultCharset, setSupportedMediaTypes, write
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
canRead, canWrite, getSupportedMediaTypes, read, write
public void setJsonPrefix(java.lang.String jsonPrefix)
setPrefixJson(boolean)
public void setPrefixJson(boolean prefixJson)
false
.
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.
setJsonPrefix(java.lang.String)
public final java.lang.Object read(java.lang.reflect.Type type, @Nullable java.lang.Class<?> contextClass, HttpInputMessage inputMessage) throws java.io.IOException, HttpMessageNotReadableException
GenericHttpMessageConverter
type
- the (potentially generic) type of object to return. This type must have
previously been passed to the canRead
method of this interface,
which must have returned true
.contextClass
- a context class for the target type, for example a class
in which the target type appears in a method signature (can be null
)inputMessage
- the HTTP input message to read fromjava.io.IOException
- in case of I/O errorsHttpMessageNotReadableException
- in case of conversion errorsprotected final java.lang.Object readInternal(java.lang.Class<?> clazz, HttpInputMessage inputMessage) throws java.io.IOException, HttpMessageNotReadableException
AbstractHttpMessageConverter
AbstractHttpMessageConverter.read(java.lang.Class<? extends T>, org.springframework.http.HttpInputMessage)
.readInternal
in class AbstractHttpMessageConverter<java.lang.Object>
clazz
- the type of object to returninputMessage
- the HTTP input message to read fromjava.io.IOException
- in case of I/O errorsHttpMessageNotReadableException
- in case of conversion errorsprotected final void writeInternal(java.lang.Object o, @Nullable java.lang.reflect.Type type, HttpOutputMessage outputMessage) throws java.io.IOException, HttpMessageNotWritableException
AbstractGenericHttpMessageConverter
AbstractGenericHttpMessageConverter.write(T, java.lang.reflect.Type, org.springframework.http.MediaType, org.springframework.http.HttpOutputMessage)
.writeInternal
in class AbstractGenericHttpMessageConverter<java.lang.Object>
o
- the object to write to the output messagetype
- the type of object to write (may be null
)outputMessage
- the HTTP output message to write tojava.io.IOException
- in case of I/O errorsHttpMessageNotWritableException
- in case of conversion errorsprotected abstract java.lang.Object readInternal(java.lang.reflect.Type resolvedType, java.io.Reader reader) throws java.lang.Exception
Reader
.resolvedType
- the resolved generic typereader
- the Reader to usejava.lang.Exception
- in case of read/parse failuresprotected abstract void writeInternal(java.lang.Object o, @Nullable java.lang.reflect.Type type, java.io.Writer writer) throws java.lang.Exception
Writer
.o
- the object to write to the output messagetype
- the type of object to write (may be null
)writer
- the Writer to usejava.lang.Exception
- in case of write failures