Search code examples
javaunirest

How can I get a List of objects using Unirest for Java?


I can use Unirest to get an object of my own class like this:

HttpResponse<Item> itemResponse = Unirest.get("http://localhost:8080/item").asObject(Item.class);

I can also set the type parameter to List, which does give me a list of hash maps, but I'd like to get a list of items instead. Is this possible?


Solution

  • Don't know if you're still waiting for an answer, but you should use an array. Like this;

    HttpResponse<Item[]> itemResponse = Unirest.get("http://localhost:8080/item").asObject(Item[].class);