Class JacksonJsonHttpMessageConverter
java.lang.Object
org.springframework.http.converter.AbstractHttpMessageConverter<Object>
org.springframework.http.converter.AbstractSmartHttpMessageConverter<Object>
org.springframework.http.converter.AbstractJacksonHttpMessageConverter<tools.jackson.databind.json.JsonMapper>
org.springframework.http.converter.json.JacksonJsonHttpMessageConverter
- All Implemented Interfaces:
HttpMessageConverter<Object>, SmartHttpMessageConverter<Object>
public class JacksonJsonHttpMessageConverter
extends AbstractJacksonHttpMessageConverter<tools.jackson.databind.json.JsonMapper>
Implementation of
HttpMessageConverter
that can read and write JSON using Jackson 3.x's
JsonMapper.
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 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 AbstractJacksonHttpMessageConverter
defaultMapperFields inherited from class AbstractHttpMessageConverter
logger -
Constructor Summary
ConstructorsConstructorDescriptionConstruct a new instance with aJsonMappercustomized with theJacksonModules found byMapperBuilder.findModules(ClassLoader)andProblemDetailJacksonMixin.JacksonJsonHttpMessageConverter(tools.jackson.databind.json.JsonMapper mapper) Construct a new instance with the providedJsonMapper.JacksonJsonHttpMessageConverter(tools.jackson.databind.json.JsonMapper.Builder builder) Construct a new instance with the providedJsonMapper.Buildercustomized with theJacksonModules found byMapperBuilder.findModules(ClassLoader)andProblemDetailJacksonMixin. -
Method Summary
Modifier and TypeMethodDescriptionReturn the supported media type(s) forProblemDetail.voidsetJsonPrefix(String jsonPrefix) Specify a custom prefix to use for this view's JSON output.voidsetPrefixJson(boolean prefixJson) Indicate whether the JSON output by this view should be prefixed with ")]}', ".protected voidwritePrefix(tools.jackson.core.JsonGenerator generator, Object object) Write a prefix before the main content.Methods inherited from class AbstractJacksonHttpMessageConverter
canRead, canWrite, customizeReader, customizeWriter, getCharset, getJavaType, getJsonEncoding, getMapper, getMappersForType, getSupportedMediaTypes, read, readInternal, registerMappersForType, setSupportedMediaTypes, supportsRepeatableWrites, writeInternal, writeSuffixMethods inherited from class AbstractSmartHttpMessageConverter
canWrite, supports, write, writeInternalMethods inherited from class AbstractHttpMessageConverter
addDefaultHeaders, canRead, canRead, canWrite, getContentLength, getDefaultCharset, getDefaultContentType, getSupportedMediaTypes, read, setDefaultCharset, writeMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface HttpMessageConverter
getSupportedMediaTypesMethods inherited from interface SmartHttpMessageConverter
canRead, read, write
-
Constructor Details
-
JacksonJsonHttpMessageConverter
public JacksonJsonHttpMessageConverter()Construct a new instance with aJsonMappercustomized with theJacksonModules found byMapperBuilder.findModules(ClassLoader)andProblemDetailJacksonMixin. -
JacksonJsonHttpMessageConverter
public JacksonJsonHttpMessageConverter(tools.jackson.databind.json.JsonMapper.Builder builder) Construct a new instance with the providedJsonMapper.Buildercustomized with theJacksonModules found byMapperBuilder.findModules(ClassLoader)andProblemDetailJacksonMixin.- See Also:
-
JacksonJsonHttpMessageConverter
public JacksonJsonHttpMessageConverter(tools.jackson.databind.json.JsonMapper mapper) Construct a new instance with the providedJsonMapper.- 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:AbstractJacksonHttpMessageConverterReturn the supported media type(s) forProblemDetail. By default, an empty list, unless overridden in subclasses.- Overrides:
getMediaTypesForProblemDetailin classAbstractJacksonHttpMessageConverter<tools.jackson.databind.json.JsonMapper>
-
writePrefix
Description copied from class:AbstractJacksonHttpMessageConverterWrite a prefix before the main content.- Overrides:
writePrefixin classAbstractJacksonHttpMessageConverter<tools.jackson.databind.json.JsonMapper>- Parameters:
generator- the generator to use for writing content.object- the object to write to the output message
-