public class MappingJackson2HttpMessageConverter extends AbstractJackson2HttpMessageConverter
HttpMessageConverter
that
can read and write JSON using Jackson 2.x'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.
Compatible with Jackson 2.1 and higher.
DEFAULT_CHARSET, objectMapper
logger
Constructor and Description |
---|
MappingJackson2HttpMessageConverter()
Construct a new
MappingJackson2HttpMessageConverter . |
Modifier and Type | Method and Description |
---|---|
void |
setJsonPrefix(String jsonPrefix)
Specify a custom prefix to use for this view's JSON output.
|
void |
setPrefixJson(boolean prefixJson)
Indicate whether the JSON output by this view should be prefixed with "{} &&".
|
protected void |
writePrefix(JsonGenerator generator,
Object object)
Write a prefix before the main content.
|
protected void |
writeSuffix(JsonGenerator generator,
Object object)
Write a suffix after the main content.
|
canRead, canRead, canWrite, getContentLength, getDefaultContentType, getJavaType, getJsonEncoding, getObjectMapper, read, readInternal, setObjectMapper, setPrettyPrint, supports, writeInternal
canRead, canWrite, getSupportedMediaTypes, read, setSupportedMediaTypes, write
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
getSupportedMediaTypes, read, write
public MappingJackson2HttpMessageConverter()
MappingJackson2HttpMessageConverter
.public void setJsonPrefix(String jsonPrefix)
setPrefixJson(boolean)
public void setPrefixJson(boolean prefixJson)
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.
setJsonPrefix(java.lang.String)
protected void writePrefix(JsonGenerator generator, Object object) throws IOException
AbstractJackson2HttpMessageConverter
writePrefix
in class AbstractJackson2HttpMessageConverter
generator
- the generator to use for writing content.object
- the object to write to the output message.IOException
protected void writeSuffix(JsonGenerator generator, Object object) throws IOException
AbstractJackson2HttpMessageConverter
writeSuffix
in class AbstractJackson2HttpMessageConverter
generator
- the generator to use for writing content.object
- the object to write to the output message.IOException