Using Jackson as Jersey client serializer

后端 未结 6 1954
暖寄归人
暖寄归人 2021-01-30 13:23

Is it possible to use Jackson as the serializer/marshaller for JSON data instead of JAXB when using Jersey Client API?

If so how to configure it?

6条回答
  •  太阳男子
    2021-01-30 13:52

    I ran into similar issue, but for me none of the suggestions given here worked. What worked for me was below piece of code:

    import javax.ws.rs.client.ClientBuilder;
    import javax.ws.rs.client.Client;
    ...
    
    ClientBuilder clientBuilder = ClientBuilder.newBuilder()
    clientBuilder.register(JacksonFeature.class);
    ...
    Client client = clientBuilder.build();
    

    The key change was usage of JacksonFeature.class - it comes from jersey-media-json-jackson-x.yy.jar

    I got clue to use this solution from this article - http://www.baeldung.com/jersey-jax-rs-client

提交回复
热议问题