sunmingtao / sample-code

3 stars 4 forks source link

How to use Resttemplate to convert a list of json objects to a list of Java objects? #264

Closed sunmingtao closed 3 years ago

sunmingtao commented 3 years ago

https://projects.fivethirtyeight.com/soccer-predictions/forecasts/2020_la-liga_matches.json

String url = String.format(SOCCER_DATA_URL_TEMPLATE, 2020, League.EPL.getName());
RestTemplate restTemplate = new RestTemplate();
ResponseEntity<List<RawMatch>> actualExample = restTemplate.exchange(url, HttpMethod.GET,
                null, new ParameterizedTypeReference<>() {});
List<RawMatch> exampleList = actualExample.getBody();
exampleList.forEach(System.out::println);