Map JSON To List<Map<<String, Object>>

Pranay Kumar :

I have a JSON of the format

[{
    "id" : "a01",
    "name" : "random1",
    "val" : "random2"

},
{
    "id" : "a03",
    "name" : "random3",
    "val" : "random4"
}]

I need to map it to a List holding various Map objects. How do I achieve it?

Even if I am able to convert this JSON to a List of String of the form

{
    "id" : "a01",
    "name" : "random1",
    "val" : "random2"

}

then I have a method to convert each individual String to a Map.

Manos Nikolaidis :

You will need to pass a TypeReference to readValue with the desired result type:

ObjectMapper mapper = new ObjectMapper();
List<Map<String, Object>> data = mapper.readValue(json, new TypeReference<List<Map<String, Object>>>(){});

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Unchecked cast on a Map<String, Object> (JSON converted to Map with Jackson)

Comparing a List<Map<String, String>> to a List<Map<String, Object>> Java

List<Map<String,String>> vs List<Object>

List<Object> to Map<String, Map<String,List<Object>>>

How to define the size of List<Map<String, Object>>?

json string with multiple types to Map[String, Object]

Sorting List<Map<String, Object>>

Unable to convert Json string to Map<String, Object>

How to Convert List<Map<String, Object>> to List<Map<String, String>>

How to Convert a List Into Map of Map Map<String, Map<String,Object>>

Convert Map<Integer, List<Object>> to Map<Integer, Map<String, Map<LocalDate, Integer>>> using Java stream API

Sort by value List<Map<String,Object>>

Java 8 collect to Map<String, List<Object>>

How to add Map<String, string> into Map<String, List<Object>> in java

AsyncTask <Map<String, List<Object>>

Convert List<Map<String, Object>> to String[][]

How to group List<Map<String,Object>> to Map<String,List<Map<String,Object>> in Java8

Convert List<Map<String, Object>> to Map<String, List<Map<String, Object>>> using Java 8 streams API

Map custom list of object as json in Entity Framework

Map list in React using typescript json object

How to convert list map to json string and json to list map

Convert Map<String, Object> to Map<String, List<Object>>

Convert byte[] to List<Map<String, Object>>

Proper way to Deserialize JSon String int List<Map<String, Object>>

How to convert List<Map<String,Object>> to Map<String, String>?

Group and Aggregate List of Map<String, Object>

Iterating through a List<Map<String, Object>> map in Thymeleaf

how to combine two List<Map<String,Object>>

Convert JSON object of array to Map of List<Map<String, dynamic>> with dynamic is a List<Object> in Flutter

TOP Ranking

HotTag

Archive