java.lang.Object | ||
↳ | org.springframework.http.converter.AbstractHttpMessageConverter<T> | |
↳ | org.springframework.http.converter.json.MappingJacksonHttpMessageConverter |
Implementation of HttpMessageConverter
that can read and write JSON using Jackson's ObjectMapper.
This converter can be used to bind to typed beans, or untyped HashMap
instances.
By default, this converter supports application/json
. This can be overridden by setting the
supportedMediaTypes
property.
Fields | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
DEFAULT_CHARSET |
[Expand]
Inherited Fields | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class
org.springframework.http.converter.AbstractHttpMessageConverter
|
Public Constructors | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Construct a new
BindingJacksonHttpMessageConverter . |
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Indicates whether the given class can be read by this converter.
This implementation checks if the given class is | |||||||||||
Indicates whether the given class can be written by this converter.
This implementation checks if the given class is | |||||||||||
Sets the
ObjectMapper for this view. | |||||||||||
Indicates whether the JSON output by this view should be prefixed with "{} &&".
|
Protected Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Returns the Jackson JavaType for the specific class.
| |||||||||||
Abstract template method that reads the actualy object.
| |||||||||||
Indicates whether the given class is supported by this converter.
| |||||||||||
Abstract template method that writes the actual body.
|
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class
org.springframework.http.converter.AbstractHttpMessageConverter
| |||||||||||
From class
java.lang.Object
| |||||||||||
From interface
org.springframework.http.converter.HttpMessageConverter
|
Construct a new BindingJacksonHttpMessageConverter
.
Indicates whether the given class can be read by this converter.
This implementation checks if the given class is supported
,
and if the supported media types
include
the given media type.
clazz | the class to test for readability |
---|---|
mediaType | the media type to read, can be null if not specified.
Typically the value of a Content-Type header. |
true
if readable; false
otherwise
Indicates whether the given class can be written by this converter.
This implementation checks if the given class is supported
,
and if the supported media types
include
the given media type.
clazz | the class to test for writability |
---|---|
mediaType | the media type to write, can be null if not specified.
Typically the value of an Accept header. |
true
if writable; false
otherwise
Sets the ObjectMapper
for this view. If not set, a default
ObjectMapper#ObjectMapper() ObjectMapper is used.
Setting a custom-configured ObjectMapper
is one way to take further control of the JSON serialization
process. For example, an extended org.codehaus.jackson.map.SerializerFactory can be configured that provides
custom serializers for specific types. The other option for refining the serialization process is to use Jackson's
provided annotations on the types to be serialized, in which case a custom-configured ObjectMapper is unnecessary.
Indicates whether the JSON output by this view should be prefixed with "{} &&". Default is 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 does not affect the evaluation of JSON, but if JSON validation is performed on the string, the prefix would need to be ignored.
Returns the Jackson JavaType for the specific class.
Default implementation returns TypeFactory#type(java.lang.reflect.Type), but this can be overridden in subclasses, to allow for custom generic collection handling. For instance:
protected JavaType getJavaType(Class<?> clazz) { if (List.class.isAssignableFrom(clazz)) { return TypeFactory.collectionType(ArrayList.class, MyBean.class); } else { return super.getJavaType(clazz); } }
clazz | the class to return the java type for |
---|
Abstract template method that reads the actualy object. Invoked from read(Class extends T>, HttpInputMessage)
.
clazz | the type of object to return |
---|---|
inputMessage | the HTTP input message to read from |
Indicates whether the given class is supported by this converter.
clazz | the class to test for support |
---|
true
if supported; false
otherwise
Abstract template method that writes the actual body. Invoked from write(T, MediaType, HttpOutputMessage)
.
o | the object to write to the output message |
---|---|
outputMessage | the message to write to |