Most APIs don't answer with sentences but with JSON, the text format they use to send data. It looks like lists and maps, but it arrives as text: response.body() is only a String.
The Jackson library's ObjectMapper reads that text with readValue and builds the real Java values it describes: a JSON […] becomes a List, and a JSON {…} becomes a Map. For a weather API whose body is {"city": "Paris", "temp": 18}:
Map<String, Object> weather = new ObjectMapper().readValue(response.body(), Map.class);
System.out.println(weather.get("city") + " " + weather.get("temp")); // Paris 18
The supplier's price list is at the path /prices. Its body is a list of products, and each product is a map with an "id", a "name" and a "price". Your program must print:
5 products
{id=1, name=Mug, price=5}
Mug costs 5
Notebook costs 3
Lamp costs 14
Pen costs 1
Plant costs 6
Your task: request /prices, turn the body into a List<Map<String, Object>> with readValue and keep it in products, print how many products there are and the first one, then loop over the list and print each product's name and price.
Assignment
Follow the Coding Tutorial to read the supplier's price list as JSON and print every product's name and price.
Hintproducts is a list of maps: size() counts its items, products.get(0) is the first map, and inside the loop each product is read with get and the key's name in quotes.
Free plan: 30 tutor messages. PRO is unlimited.
