Class JacksonJsonHttpMessageConverter
java.lang.Object
org.springframework.http.converter.AbstractHttpMessageConverter<Object>
org.springframework.http.converter.AbstractSmartHttpMessageConverter<Object>
org.springframework.http.converter.AbstractJacksonHttpMessageConverter
org.springframework.http.converter.json.JacksonJsonHttpMessageConverter
- All Implemented Interfaces:
HttpMessageConverter<Object>
,SmartHttpMessageConverter<Object>
Implementation of
HttpMessageConverter
that can read and write JSON using Jackson 3.x's
ObjectMapper
.
This converter can be used to bind to typed beans, or untyped
HashMap
instances.
By default, this converter supports application/json
and
application/*+json
with UTF-8
character set. This
can be overridden by setting the supportedMediaTypes
property.
The default constructor loads JacksonModule
s
found by MapperBuilder.findModules(ClassLoader)
.
The following hints entries are supported:
- A JSON view with a
com.fasterxml.jackson.annotation.JsonView
key and the class name of the JSON view as value. - A filter provider with a
tools.jackson.databind.ser.FilterProvider
key and the filter provider class name as value.
- Since:
- 7.0
- Author:
- Sebastien Deleuze
-
Field Summary
Fields inherited from class org.springframework.http.converter.AbstractJacksonHttpMessageConverter
defaultObjectMapper
Fields inherited from class org.springframework.http.converter.AbstractHttpMessageConverter
logger
-
Constructor Summary
ConstructorsConstructorDescriptionConstruct a new instance with aJsonMapper
customized with theJacksonModule
s found byMapperBuilder.findModules(ClassLoader)
andProblemDetailJacksonMixin
.JacksonJsonHttpMessageConverter
(ObjectMapper objectMapper) Construct a new instance with the providedObjectMapper
. -
Method Summary
Modifier and TypeMethodDescriptionReturn the supported media type(s) forProblemDetail
.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
(tools.jackson.core.JsonGenerator generator, Object object) Write a prefix before the main content.Methods inherited from class org.springframework.http.converter.AbstractJacksonHttpMessageConverter
canRead, canWrite, customizeReader, customizeWriter, getCharset, getJavaType, getJsonEncoding, getObjectMapper, getObjectMappersForType, getSupportedMediaTypes, read, readInternal, registerObjectMappersForType, setSupportedMediaTypes, supportsRepeatableWrites, writeInternal, writeSuffix
Methods inherited from class org.springframework.http.converter.AbstractSmartHttpMessageConverter
canWrite, supports, write, writeInternal
Methods inherited from class org.springframework.http.converter.AbstractHttpMessageConverter
addDefaultHeaders, canRead, canRead, canWrite, getContentLength, getDefaultCharset, getDefaultContentType, getSupportedMediaTypes, read, setDefaultCharset, write
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.springframework.http.converter.HttpMessageConverter
getSupportedMediaTypes
Methods inherited from interface org.springframework.http.converter.SmartHttpMessageConverter
canRead, read, write
-
Constructor Details
-
JacksonJsonHttpMessageConverter
public JacksonJsonHttpMessageConverter()Construct a new instance with aJsonMapper
customized with theJacksonModule
s found byMapperBuilder.findModules(ClassLoader)
andProblemDetailJacksonMixin
. -
JacksonJsonHttpMessageConverter
Construct a new instance with the providedObjectMapper
.- See Also:
-
-
Method Details
-
setJsonPrefix
Specify a custom prefix to use for this view's JSON output. Default is none.- See Also:
-
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.
- See Also:
-
getMediaTypesForProblemDetail
Description copied from class:AbstractJacksonHttpMessageConverter
Return the supported media type(s) forProblemDetail
. By default, an empty list, unless overridden in subclasses.- Overrides:
getMediaTypesForProblemDetail
in classAbstractJacksonHttpMessageConverter
-
writePrefix
Description copied from class:AbstractJacksonHttpMessageConverter
Write a prefix before the main content.- Overrides:
writePrefix
in classAbstractJacksonHttpMessageConverter
- Parameters:
generator
- the generator to use for writing content.object
- the object to write to the output message
-