从3.1 M1开始,您可以通过注册的
HttpMessageConverters子元素来指定杰克逊自定义配置
mvc:annotation-driven。
请参阅Spring 3.1
MVC命名空间的改进
请参阅SPR-7504,使其更轻松地将新的消息转换器添加到AnnotationMethodHandlerAdapter
范例:
<bean id="jacksonObjectMapper" > </bean><mvc:annotation-driven> <mvc:message-converters> <bean ><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); } }
SerializationConfig
.withDateFormatIn 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)
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)