0

I have gone through some of the questions here and their answers like this one which tells us how to extract a list of objects from a restTemplate response. It does not, however, solve my problem which is, I have an Entry class

@JsonIgnoreProperties(ignoreUnknown = true)
public class Entry {


    private String API;
    private String Description;
    private String Auth;
    private boolean HTTPS;
    private String Cors;
    private String Link;
    private String Category;
//    getters and setters
}

then I have an Entry implementation class which has

@JsonIgnoreProperties(ignoreUnknown = true)
public class EntryImpl {
    private Long count;
    private ArrayList<Entry> entries;


    public EntryImpl () {

    }
//  getters and setters
}

and here is my request implementation to consume this api

public class RestConsump {
    public static void main (String [] args) {
        RestTemplate restTemplate = new RestTemplate();
        String url = "https://api.publicapis.org/entries";
        EntryImpl entries = restTemplate.getForObject(url, EntryImpl.class);
        System.out.println(entries.getEntries().get(0)); // returns null for all entries 
        System.out.println(entries.getCount()); // prints the numbers of entries
    }
}

My question is, how do I implement it so that EntryImpl returns the list of entries and the count.

Ninety5
  • 53
  • 2
  • 5

1 Answers1

0

I executed the code above and got this response:

{API=AdoptAPet, Description=Resource to help get pets adopted, Auth=apiKey, HTTPS=true, Cors=yes, Link=https://www.adoptapet.com/public/apis/pet_list.html, Category=Animals}
1417

I used spring-web:5.3.8 for the RestTemplate, java version 15. Perhaps you are using an outdated RestTemplate?