从3.1 M1开始,您可以通过注册的HttpMessageConverters
子元素来指定杰克逊自定义配置mvc:annotation- driven
。
请参阅SPR-7504,使其更轻松地将新的消息转换器添加到AnnotationMethodHandlerAdapter
范例:
<bean id="jacksonObjectMapper" class="x.y.z.CustomObjectMapper">
</bean>
<mvc:annotation-driven>
<mvc:message-converters>
<bean class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter">
<property name="objectMapper" ref="jacksonObjectMapper" />
</bean>
</mvc:message-converters>
</mvc:annotation-driven>
CustomObjectMapper对象
@Component("jacksonObjectMapper")
public class CustomObjectMapper extends ObjectMapper {
@postconstruct
public void afterPropertiesSet() throws Exception {
SerializationConfig serialConfig = getSerializationConfig()
.withDateFormat(null);
//any other configuration
this.setSerializationConfig(serialConfig);
}
}
In addition to constructing instance with specified date format, will enable or disable Feature.WRITE_DATES_AS_TIMESTAMPS (enable if format set as null; disable if non-null)