What is the maven dependency to use Jackson2ObjectMapperBuilderCustomizer? For a spring mvc project

那年仲夏 提交于 2021-01-28 03:26:48

问题


I have a Spring MVC project which does NOT USE spring-boot.

Im trying to use Jackson2ObjectMapperBuilderCustomizer in my appConfig class to configure a default date format.

I have these two dependencies in already but I'm still getting an error on the ObjectMapper? I am using spring version 4. All the examples for using the Jackson2ObjectMapperBuilderCustomizer are using spring boot which seems to not need need a dependency

        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-databind</artifactId>
            <version>2.9.8</version>
        </dependency>`

       <dependency>
            <groupId>com.fasterxml.jackson.datatype</groupId>
            <artifactId>jackson-datatype-jsr310</artifactId>
            <version>2.9.8</version>
        </dependency>`

回答1:


The class is only part of Spring Boot dependencies. If you are determined to not use any Spring Boot dependencies, you will have to look for alternatives, otherwise you can use the following:

    <!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-autoconfigure -->
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-autoconfigure</artifactId>
        <version>1.2.2.RELEASE</version>
    </dependency>



回答2:


Add jackson-datatype-jsr310 dependency . its an alternative for non spring boot projects.

https://mvnrepository.com/artifact/com.fasterxml.jackson.datatype/jackson-datatype-jsr310/2.10.1



来源:https://stackoverflow.com/questions/55572936/what-is-the-maven-dependency-to-use-jackson2objectmapperbuildercustomizer-for-a

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!