Below are the dependencies version which used while writing this note
Jersey
<dependency>
<groupId>org.glassfish.jersey.core</groupId>
<artifactId>jersey-client</artifactId>
<version>2.26</version>
</dependency>
Jackson
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-json-jackson</artifactId>
<version>2.26</version>
</dependency>
Genson
<dependency>
<groupId>com.owlike</groupId>
<artifactId>genson</artifactId>
<version>1.5</version>
</dependency>
After request finished, you can try to deserialize response body into an object with response.readEntity
.
If you facing an issue during deserialization caused by owlike.genson even you does not import genson into your entity class, try to disable the genson in JAX-RS on initial client build.
ClientConfig config = new ClientConfig().register(new GensonJaxRSFeature().disable());
client = ClientBuilder.newBuilder()
.withConfig(config)
.build();
If you try to deserialize a json to an object and the object doesn't filled by what contained on a given json, check your target class maybe they don't have setter method for it null fields.
Don't forget that the POJO require setter and getter to reflect the json object during deserialization.
If you want to retreive a list that contains of different object into POJO class, first thing you need to do is creating interface to representing the differrent objects you want to fullfill with the list.
Second, create your each object class implementing the interface then define the collection type field which will contains the interface into your parent POJO. We are going to use Jackson to deserialize the parent POJO so the defined list field need custom deserializer to fetch the child tree from the json input
...