I'd like to parse a JSON Array using the native JsonParser available in Spring Boot:
String url="https://restservice.com";
RestTemplate restTemplate = new RestTemplate();
String resp = restTemplate.getForObject(url, String.class);
JsonParser springParser = JsonParserFactory.getJsonParser();
Map<String, Object> map = springParser.parseMap(resp);
That works if there's just one item in the Array. If multiple items are returned, an exception is thrown:
Caused by: org.springframework.boot.json.JsonParseException: Cannot parse JSON
at org.springframework.boot.json.AbstractJsonParser.tryParse(AbstractJsonParser.java:60) ~[spring-boot-2.1.0.RELEASE.jar!/:2.1.0.RELEASE]
at org.springframework.boot.json.JacksonJsonParser.parseMap(JacksonJsonParser.java:55) ~[spring-boot-2.1.0.RELEASE.jar!/:2.1.0.RELEASE]
at com.example.samplewebapp.DemoApplication.lambda$demo$2(DemoApplication.java:50) [classes!/:0.0.1-SNAPSHOT]
at org.springframework.boot.SpringApplication.callRunner(SpringApplication.java:813) [spring-boot-2.1.0.RELEASE.jar!/:2.1.0.RELEASE]
... 13 common frames omitted
Caused by: com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot deserialize instance of `java.util.LinkedHashMap` out of START_ARRAY token
What is the correct API to return a List of Map JSON objects?
parseList?Cannot deserialize instance of java.util.LinkedHashMap out of START_ARRAY tokenIt would be easier to help you if you could provide the input and the expected output. stackoverflow.com/help/mcve