您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

在Spring 3.1中我应在哪里指定Jackson SerializationConfig.Feature设置

在Spring 3.1中我应在哪里指定Jackson SerializationConfig.Feature设置

从3.1 M1开始,您可以通过注册HttpMessageConverters子元素来指定杰克逊自定义配置mvc:annotation- driven

请参阅Spring 3.1 MVC命名空间的改进

请参阅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)

Java 2022/1/1 18:14:18 有632人围观

撰写回答


你尚未登录,登录后可以

和开发者交流问题的细节

关注并接收问题和回答的更新提醒

参与内容的编辑和改进,让解决方法与时俱进

请先登录

推荐问题


联系我
置顶