java - How register JacksonFeature on ClientConfig -


how give json on resfull java project using jackson?

following article http://www.vogella.com/tutorials/rest/article.html (8.4. create client ) create rest project in java, says return json proceed like:

public class todotest {    public static void main(string[] args) {     clientconfig config = new new clientconfig().register(jacksonfeature.class);     client client = clientbuilder.newclient(config);      webtarget target = client.target(getbaseuri());     system.out.println(target.path("rest").path("todo").request()         .accept(mediatype.application_json).get(string.class));   }    private static uri getbaseuri() {     return uribuilder.fromuri("http://localhost:8080_com.vogella.jersey.jaxb").build();   } }   @xmlrootelement public class todo {     private string id;     private string summary;     private string description;     //getter/setter } 

but jacksonfeature.class not in jackson.jar. i'm using

jackson-annotations-2.8.2.jar jackson-core-2.8.2.jar jackson-databind-2.8.2.jar jackson-jaxrs-base-2.8.2.jar jackson-jaxrs-json-provider-2.8.2.jar jackson-module-jaxb-annotations-2.8.2.jar 

how solve it?

jacksonfeature jersey set of libraries (the jersey-media-json-jackson artifact in maven), not jackson. see documentation here. way tell jersey "please use jackson libraries json parsing , serialization", , not part of jackson.

it seems 1 of ways jersey use jackson. this article states placing following xml in pom.xml enough jersey use jackson. suggests better way , jersey documentation may wrong encourage use of jacksonfeature.class. linked article recommends not use jersey-media-json-jackson.

<dependency>     <groupid>com.fasterxml.jackson.core</groupid>     <artifactid>jackson-databind</artifactid>     <version>${jackson.version}</version> </dependency> <dependency>     <groupid>com.fasterxml.jackson.jaxrs</groupid>     <artifactid>jackson-jaxrs-json-provider</artifactid>     <version>${jackson.version}</version> </dependency> 

Comments

Popular posts from this blog

javascript - Thinglink image not visible until browser resize -

firebird - Error "invalid transaction handle (expecting explicit transaction start)" executing script from Delphi -

mongodb - How to keep track of users making Stripe Payments -