DAO for fetching organizations and departments through a REST API
On the advise of a person from reddit here : Java code refactoring, in order to get rid of code duplication

I tried something like this :

private &lt;T0, T1 extends ResourceSupport&lt;T0&gt;&gt; List&lt;T0&gt; getResources(Class&lt;T0&gt; clazz1, Class&lt;T1&gt; clazz2, String path, GenericType&lt;Resources&lt;T1&gt;&gt; genericInstance ) {
    List&lt;T0&gt; results = new ArrayList();
    Client client = ClientHelper.createClient(); 
    Resources&lt;T1&gt; response = client
            .target(restApiRoot + path)
            .request(MediaType.APPLICATION_JSON)
            .get(genericInstance);
    List&lt;T1&gt; resources = response.getContent();
    for (T1 resource : resources) {
        results.add(resource.getEntity());
    }
    return results;
}


@XmlRootElement
@Getter
@Setter
public class OrganizationResource extends ResourceSupport&lt;Organization&gt; {

    @XmlElement(name="organization")
    private Organization entity;

    @Override
    public Organization getEntity() {
        return entity;
    }
}


@XmlRootElement
@Getter
@Setter
public abstract class ResourceSupport&lt;T&gt;  {
    @XmlElement(name="link")
    private List&lt;Link&gt; links;

    public abstract T getEntity();
}


Called like this :

GenericType&lt;Resources&lt;OrganizationResource&gt;&gt; genericInstance = new GenericType&lt;Resources&lt;OrganizationResource&gt;&gt;(){};
List&lt;Organization&gt; list = getResources(Organization.class, OrganizationResource.class, "organizations", genericInstance); 


For information, the rest api response is :

{
  "links": [],
    "content": [
        {
            "organization": {
                "id": "GES",
                "code": "GES",
                "name": "GES XX1",
                "legalNumber": "654654654"
            },
            "links": [
              {
                  "rel": "self",
                  "href": "https://server:8443/api/organizations/GES"
              },
              {
                  "rel": "organizations",
                  "href": "https://server:8443/api/organizations"
              },
            ]
        },
        {
            "organization": {
                "id": "PRO",
                "code": "PRO",
                "name": "PRO XX1",
                "legalNumber": "54545646"
            },
            "links": [ ... ]
        ...   
    ]
}