gpt4 book ai didi

java - 用于处理 DateTime 的 CustomJacksonMapper 配置在 Spring 4.1.5 上不起作用

转载 作者:太空宇宙 更新时间:2023-11-04 12:27:10 24 4
gpt4 key购买 nike

以下是我所做的配置:

我的配置文件:

<mvc:annotation-driven>
<mvc:message-converters>
<!-- Support for Joda Time -->
<bean class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter">
<property name="objectMapper" ref="customJacksonMapper" />
</bean>
</mvc:message-converters>
</mvc:annotation-driven>

我的扩展对象的类

@Component("customJacksonMapper")
public class CustomJacksonMapper extends ObjectMapper {
/** The Constant serialVersionUID. */
private static final long serialVersionUID = 1L;

/**
* Instantiates a new custom jackson mapper.
*
* RegisterModule = Registar o módulo do JodaTime.
* Locale = Padrão portugues Brasil.
* TimeZone = Converte para o timezone de São Paulo.
*
*/
public CustomJacksonMapper() {
this.registerModule(new JodaModule());
this.setLocale(new Locale("pt_BR"));
this.setTimeZone(TimeZone.getTimeZone("America/Sao_Paulo"));
this.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS , false);
this.setSerializationInclusion(JsonInclude.Include.NON_NULL);
}

}

通过此配置,正如我在很多帖子中读到的那样,日期应该以 Json 的正确格式返回,但我得到的是以下内容:

{"date": 1467920285301}

我做错了什么?

最佳答案

尝试将此行添加到构造函数中:

this.setDateFormat(new ISO8601DateFormat());

关于java - 用于处理 DateTime 的 CustomJacksonMapper 配置在 Spring 4.1.5 上不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38254085/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com