Latest Jackson Integration Improvements in Spring - DZone Java
Prior to Spring Framework 4.1.1, Jackson HttpMessageConverter
s were usingObjectMapper
default configuration. In order to provide a better and easily customizable default configuration, a new Jackson2ObjectMapperBuilder
has been introduced. It is the JavaConfig equivalent of the well known Jackson2ObjectMapperFactoryBean
used in XML configuration.
Jackson2ObjectMapperBuilder
provides a nice API to customize various Jackson settings while retaining Spring Framework provided default ones. It also allows to createObjectMapper
and XmlMapper
instances based on the same configuration.
Both Jackson2ObjectMapperBuilder
and Jackson2ObjectMapperFactoryBean
define a better Jackson default configuration. For example, theDeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES
property set to false, in order to allow deserialization of JSON objects with unmapped properties.
Jackson support for Java 8 Date & Time API data types is automatically registered when Java 8 is used and jackson-datatype-jsr310
is on the classpath. Joda-Time support is registered as well when jackson-datatype-joda
is part of your project dependencies.
These classes also allow you to register easily Jackson mixins, modules, serializers or even property naming strategy like PropertyNamingStrategy.CAMEL_CASE_TO_LOWER_CASE_WITH_UNDERSCORES
if you want to have your userName
java property translated to user_name
in JSON.
Read full article from Latest Jackson Integration Improvements in Spring - DZone Java
No comments:
Post a Comment