getContext() method of CustomContextResolver is not called by Jackson

后端 未结 2 1406
自闭症患者
自闭症患者 2021-01-23 09:02

I am struggling with this issue for days now and have no clue how to solve this. Any quick help will be grateful. I need to convert LocalDate from JSON string which I am receiv

相关标签:
2条回答
  • 2021-01-23 09:32

    I had exactly the same problem @peeskillet describes in question comment.

    I was using Jackson dependencies from version 2 and jackson-jaxrs from version 1.

    All solved when moved all dependencies to version 2.

    0 讨论(0)
  • 2021-01-23 09:38

    If you are using Maven you can add following two maven dependency.

            <dependency>
                <groupId>com.fasterxml.jackson.jaxrs</groupId>
                <artifactId>jackson-jaxrs-json-provider</artifactId>
            </dependency>
    
            <dependency>
                <groupId>com.fasterxml.jackson.datatype</groupId>
                <artifactId>jackson-datatype-jdk8</artifactId>
            </dependency>
    

    And Add following code snippet.

    @Configuration
    public class CxfConfig {
    
        @Component
        @javax.ws.rs.ext.Provider
        public static class JacksonJaxbJsonProvider
                extends com.fasterxml.jackson.jaxrs.json.JacksonJaxbJsonProvider {
    
            @Autowired
            private ObjectMapper objectMapper;
    
            @PostConstruct
            public void init() {
    
                objectMapper.registerModule(new Jdk8Module());
    
            }
    
        }
    }
    
    0 讨论(0)
提交回复
热议问题