How to skip jackson timezone correction in spring-mvc?

后端 未结 2 1721
说谎
说谎 2021-02-06 07:46

I want to configure jackson to output any date/time values with the following format:

spring.jackson.date-format=yyyy-MM-dd\'T\'HH:mm:ss

<
2条回答
  •  后悔当初
    2021-02-06 07:52

    Finally it turned out the simples way is to just set the jacksons ObjectMapper (which uses UTC by defaut) timezone to the jvm defaults:

    @Bean
    public Jackson2ObjectMapperBuilderCustomizer init() {
        return new Jackson2ObjectMapperBuilderCustomizer() {
            @Override
            public void customize(Jackson2ObjectMapperBuilder builder) {
                builder.timeZone(TimeZone.getDefault());
            }
        };
    }
    

    I'd appreciate if anybody knows how I can achieve the same by just using the spring.jackson.time-zone application.property.

提交回复
热议问题