Can not deserialize instance of java.util.HashMap out of START_ARRAY token

It seem's that your file is representing a List of objects with Name and CreationDate fields.

So you have to just use List instead of HashMap to ObjectMapper, code is mentioned below:

List<HashMap> dataAsMap = objectMapper.readValue(mapData, List.class);

This exception is raised because you're trying to deserialize a List in a Map.

The solution is create a TypeReference of List<Map<String, Object>>:

List<Map<String, Object>> myObjects = 
          mapper.readValue(mapData , new TypeReference<List<Map<String, Object>>>(){});

Create a simple pojo Class First

class MyClass
{
@JsonProperty
private String Name;
@JsonProperty
private String CreationDate;
}

and use this code...

byte[] mapData = Files.readAllBytes(Paths.get("process.txt"));

ObjectMapper objectMapper=new ObjectMapper();
//add this line  
objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);    
List<MyClass> myObjects = mapper.readValue(mapData , new TypeReference<List<MyClass>>(){});

or

byte[] mapData = Files.readAllBytes(Paths.get("process.txt"));

ObjectMapper objectMapper=new ObjectMapper();
 //add this line  
objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);    

List<MyClass> myObjects = mapper.readValue(mapData , mapper.getTypeFactory().constructCollectionType(List.class, MyClass.class));

myObjects will contains the List of MyClass. Now you can access this list as per your requirement.

Tags:

Java

Json

Jackson