spring-framework / org.springframework.http.converter.json / AbstractJackson2HttpMessageConverter

AbstractJackson2HttpMessageConverter

abstract class AbstractJackson2HttpMessageConverter : AbstractGenericHttpMessageConverter<Any>

Abstract base class for Jackson based and content type independent HttpMessageConverter implementations.

Compatible with Jackson 2.9 and higher, as of Spring 5.0.

Author
Arjen Poutsma

Author
Keith Donald

Author
Rossen Stoyanchev

Author
Juergen Hoeller

Author
Sebastien Deleuze

Since
4.1

Properties

DEFAULT_CHARSET

static val DEFAULT_CHARSET: Charset

Functions

canRead

open fun canRead(clazz: Class<*>, mediaType: MediaType): Boolean
open fun canRead(type: Type, contextClass: Class<*>, mediaType: MediaType): Boolean

canWrite

open fun canWrite(clazz: Class<*>, mediaType: MediaType): Boolean

getObjectMapper

open fun getObjectMapper(): ObjectMapper

Return the underlying ObjectMapper for this view.

read

open fun read(type: Type, contextClass: Class<*>, inputMessage: HttpInputMessage): Any

setObjectMapper

open fun setObjectMapper(objectMapper: ObjectMapper): Unit

Set the ObjectMapper for this view. If not set, a default ObjectMapper is used.

Setting a custom-configured ObjectMapper is one way to take further control of the JSON serialization process. For example, an extended com.fasterxml.jackson.databind.ser.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.

setPrettyPrint

open fun setPrettyPrint(prettyPrint: Boolean): Unit

Whether to use the DefaultPrettyPrinter when writing JSON. This is a shortcut for setting up an ObjectMapper as follows:

 ObjectMapper mapper = new ObjectMapper(); mapper.configure(SerializationFeature.INDENT_OUTPUT, true); converter.setObjectMapper(mapper); 

Inheritors

MappingJackson2CborHttpMessageConverter

open class MappingJackson2CborHttpMessageConverter : AbstractJackson2HttpMessageConverter

Implementation of org.springframework.http.converter.HttpMessageConverter that can read and write CBOR data format using the dedicated Jackson 2.x extension.

By default, this converter supports "application/cbor" media type. This can be overridden by setting the supportedMediaTypes property.

The default constructor uses the default configuration provided by Jackson2ObjectMapperBuilder.

Compatible with Jackson 2.9 and higher.

MappingJackson2HttpMessageConverter

open class MappingJackson2HttpMessageConverter : AbstractJackson2HttpMessageConverter

Implementation of org.springframework.http.converter.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.

Compatible with Jackson 2.9 and higher, as of Spring 5.0.

MappingJackson2SmileHttpMessageConverter

open class MappingJackson2SmileHttpMessageConverter : AbstractJackson2HttpMessageConverter

Implementation of org.springframework.http.converter.HttpMessageConverter that can read and write Smile data format ("binary JSON") using the dedicated Jackson 2.x extension.

By default, this converter supports "application/x-jackson-smile" media type. This can be overridden by setting the supportedMediaTypes property.

The default constructor uses the default configuration provided by Jackson2ObjectMapperBuilder.

Compatible with Jackson 2.9 and higher.

MappingJackson2XmlHttpMessageConverter

open class MappingJackson2XmlHttpMessageConverter : AbstractJackson2HttpMessageConverter

Implementation of org.springframework.http.converter.HttpMessageConverter that can read and write XML using Jackson 2.x extension component for reading and writing XML encoded data.

By default, this converter supports application/xml, text/xml, and application/*+xml with UTF-8 character set. This can be overridden by setting the supportedMediaTypes property.

The default constructor uses the default configuration provided by Jackson2ObjectMapperBuilder.

Compatible with Jackson 2.9 and higher, as of Spring 5.0.