Using Jackson as Jersey client serializer

后端 未结 6 1945
暖寄归人
暖寄归人 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

    For jersey 2.22.2 and Jackson 2.7.2 gradle dependencies are:

    dependencies {
        compile("com.fasterxml.jackson.jaxrs:jackson-jaxrs-json-provider:2.7.2")
        compile("org.glassfish.jersey.core:jersey-client:2.22.2")
    }
    

    Sample client code is:

    final String    name    = "world";
    final Client    client  = ClientBuilder.newClient().register(JacksonJaxbJsonProvider.class);
    final WebTarget target  = client.target("http://localhost:8080").path("hello").path(name);
    final Message   message = target.request().get(Message.class);
    
    System.out.println(message.getWelcomeMessage()); // hello world
    

提交回复
热议问题