Class MappingJackson2HttpMessageConverter
java.lang.Object
org.springframework.http.converter.AbstractHttpMessageConverter<T>
org.springframework.http.converter.AbstractGenericHttpMessageConverter<Object>
org.springframework.http.converter.json.AbstractJackson2HttpMessageConverter
org.springframework.http.converter.json.MappingJackson2HttpMessageConverter
- All Implemented Interfaces:
- GenericHttpMessageConverter<Object>,- HttpMessageConverter<Object>
Implementation of 
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 and application/*+json
 with UTF-8 character set. This can be overridden by setting the
 supportedMediaTypes property.
 
The default constructor uses the default configuration provided by Jackson2ObjectMapperBuilder.
- Since:
- 3.1.2
- Author:
- Arjen Poutsma, Keith Donald, Rossen Stoyanchev, Juergen Hoeller, Sebastien Deleuze
- 
Field SummaryFields inherited from class org.springframework.http.converter.json.AbstractJackson2HttpMessageConverterdefaultObjectMapperFields inherited from class org.springframework.http.converter.AbstractHttpMessageConverterlogger
- 
Constructor SummaryConstructorsConstructorDescriptionConstruct a newMappingJackson2HttpMessageConverterusing default configuration provided byJackson2ObjectMapperBuilder.MappingJackson2HttpMessageConverter(ObjectMapper objectMapper) Construct a newMappingJackson2HttpMessageConverterwith a customObjectMapper.
- 
Method SummaryModifier 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(JsonGenerator generator, Object object) Write a prefix before the main content.Methods inherited from class org.springframework.http.converter.json.AbstractJackson2HttpMessageConvertercanRead, canRead, canWrite, customizeReader, customizeWriter, getCharset, getContentLength, getDefaultContentType, getJavaType, getJsonEncoding, getObjectMapper, getObjectMappersForType, getSupportedMediaTypes, logWarningIfNecessary, read, readInternal, registerObjectMappersForType, setObjectMapper, setPrettyPrint, setSupportedMediaTypes, supportsRepeatableWrites, writeInternal, writeSuffixMethods inherited from class org.springframework.http.converter.AbstractGenericHttpMessageConvertercanWrite, supports, write, writeInternalMethods inherited from class org.springframework.http.converter.AbstractHttpMessageConverteraddDefaultHeaders, canRead, canWrite, getDefaultCharset, getSupportedMediaTypes, read, setDefaultCharset, writeMethods inherited from class java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.springframework.http.converter.HttpMessageConvertergetSupportedMediaTypes, read, write
- 
Constructor Details- 
MappingJackson2HttpMessageConverterpublic MappingJackson2HttpMessageConverter()Construct a newMappingJackson2HttpMessageConverterusing default configuration provided byJackson2ObjectMapperBuilder.
- 
MappingJackson2HttpMessageConverterConstruct a newMappingJackson2HttpMessageConverterwith a customObjectMapper. You can useJackson2ObjectMapperBuilderto build it easily.- See Also:
 
 
- 
- 
Method Details- 
setJsonPrefixSpecify a custom prefix to use for this view's JSON output. Default is none.- See Also:
 
- 
setPrefixJsonpublic 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:
 
- 
getMediaTypesForProblemDetailDescription copied from class:AbstractJackson2HttpMessageConverterReturn the supported media type(s) forProblemDetail. By default, an empty list, unless overridden in subclasses.- Overrides:
- getMediaTypesForProblemDetailin class- AbstractJackson2HttpMessageConverter
 
- 
writePrefixDescription copied from class:AbstractJackson2HttpMessageConverterWrite a prefix before the main content.- Overrides:
- writePrefixin class- AbstractJackson2HttpMessageConverter
- Parameters:
- generator- the generator to use for writing content.
- object- the object to write to the output message.
- Throws:
- IOException
 
 
-