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

Package org.springframework.http.converter.json

Types

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.

GsonBuilderUtils

abstract class GsonBuilderUtils

A simple utility class for obtaining a Google Gson 2.x GsonBuilder which Base64-encodes byte[] properties when reading and writing JSON.

GsonHttpMessageConverter

open class GsonHttpMessageConverter : AbstractJsonHttpMessageConverter

Implementation of org.springframework.http.converter.HttpMessageConverter that can read and write JSON using the Google Gson library.

This converter can be used to bind to typed beans or untyped HashMaps. By default, it supports application/json and application/*+json with UTF-8 character set.

Tested against Gson 2.6; compatible with Gson 2.0 and higher.

Jackson2ObjectMapperFactoryBean

open class Jackson2ObjectMapperFactoryBean : FactoryBean<ObjectMapper>, BeanClassLoaderAware, ApplicationContextAware, InitializingBean

A FactoryBean for creating a Jackson 2.x ObjectMapper (default) or XmlMapper (createXmlMapper property set to true) with setters to enable or disable Jackson features from within XML configuration.

It customizes Jackson defaults properties with the following ones:

Example usage with MappingJackson2HttpMessageConverter:

 <bean class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter"> <property name="objectMapper"> <bean class="org.springframework.http.converter.json.Jackson2ObjectMapperFactoryBean" p:autoDetectFields="false" p:autoDetectGettersSetters="false" p:annotationIntrospector-ref="jaxbAnnotationIntrospector" /> </property> </bean> 

Example usage with MappingJackson2JsonView:

 <bean class="org.springframework.web.servlet.view.json.MappingJackson2JsonView"> <property name="objectMapper"> <bean class="org.springframework.http.converter.json.Jackson2ObjectMapperFactoryBean" p:failOnEmptyBeans="false" p:indentOutput="true"> <property name="serializers"> <array> <bean class="org.mycompany.MyCustomSerializer" /> </array> </property> </bean> </property> </bean> 

In case there are no specific setters provided (for some rarely used options), you can still use the more general methods #setFeaturesToEnable and #setFeaturesToDisable.

 <bean class="org.springframework.http.converter.json.Jackson2ObjectMapperFactoryBean"> <property name="featuresToEnable"> <array> <util:constant static-field="com.fasterxml.jackson.databind.SerializationFeature.WRAP_ROOT_VALUE"/> <util:constant static-field="com.fasterxml.jackson.databind.SerializationFeature.CLOSE_CLOSEABLE"/> </array> </property> <property name="featuresToDisable"> <array> <util:constant static-field="com.fasterxml.jackson.databind.MapperFeature.USE_ANNOTATIONS"/> </array> </property> </bean> 

It also automatically registers the following well-known modules if they are detected on the classpath:

In case you want to configure Jackson's ObjectMapper with a custom Module, you can register one or more such Modules by class name via #setModulesToInstall:

 <bean class="org.springframework.http.converter.json.Jackson2ObjectMapperFactoryBean"> <property name="modulesToInstall" value="myapp.jackson.MySampleModule,myapp.jackson.MyOtherModule"/> </bean 

Compatible with Jackson 2.6 and higher, as of Spring 4.3.

JsonbHttpMessageConverter

open class JsonbHttpMessageConverter : AbstractJsonHttpMessageConverter

Implementation of org.springframework.http.converter.HttpMessageConverter that can read and write JSON using the JSON Binding API.

This converter can be used to bind to typed beans or untyped HashMaps. By default, it supports application/json and application/*+json with UTF-8 character set.

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.

MappingJacksonInputMessage

open class MappingJacksonInputMessage : HttpInputMessage

HttpInputMessage that can eventually stores a Jackson view that will be used to deserialize the message.

MappingJacksonValue

open class MappingJacksonValue

A simple holder for the POJO to serialize via MappingJackson2HttpMessageConverter along with further serialization instructions to be passed in to the converter.

On the server side this wrapper is added with a ResponseBodyInterceptor after content negotiation selects the converter to use but before the write.

On the client side, simply wrap the POJO and pass it in to the RestTemplate.

SpringHandlerInstantiator

open class SpringHandlerInstantiator : HandlerInstantiator

Allows for creating Jackson (JsonSerializer, JsonDeserializer, KeyDeserializer, TypeResolverBuilder, TypeIdResolver) beans with autowiring against a Spring ApplicationContext.

As of Spring 4.3, this overrides all factory methods in HandlerInstantiator, including non-abstract ones and recently introduced ones from Jackson 2.4 and 2.5: for ValueInstantiator, ObjectIdGenerator, ObjectIdResolver, PropertyNamingStrategy, Converter, VirtualBeanPropertyWriter.