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

Ashish

I am facing issue while parsing JSON using jackson-core-2.7.3.jar You can get them from here http://repo1.maven.org/maven2/com/fasterxml/jackson/core/

My JSON File is

[
    {
        "Name":  "System Idle Process",
        "CreationDate":  "20160409121836.675345+330"
    },
    {
        "Name":  "System",
        "CreationDate":  "20160409121836.675345+330"
    },
    {
        "Name":  "smss.exe",
        "CreationDate":  "20160409121836.684966+330"
    }
]

and the Java Code is by which I am trying to parse this is

byte[] mapData = Files.readAllBytes(Paths.get("process.txt"));
Map<String,String> myMap = new HashMap<String, String>();
ObjectMapper objectMapper=new ObjectMapper();
myMap = objectMapper.readValue(mapData, HashMap.class);
System.out.println("Map is: "+myMap);

But upon execution I am getting the error

com.fasterxml.jackson.databind.JsonMappingException: Can not deserialize instance of java.util.HashMap out of START_ARRAY token
 at [Source: [B@34ce8af7; line: 1, column: 1]
at com.fasterxml.jackson.databind.JsonMappingException.from(JsonMappingException.java:216)
at com.fasterxml.jackson.databind.DeserializationContext.mappingException(DeserializationContext.java:873)
at com.fasterxml.jackson.databind.DeserializationContext.mappingException(DeserializationContext.java:869)
at com.fasterxml.jackson.databind.deser.std.StdDeserializer._deserializeFromEmpty(StdDeserializer.java:874)
at com.fasterxml.jackson.databind.deser.std.MapDeserializer.deserialize(MapDeserializer.java:337)
at com.fasterxml.jackson.databind.deser.std.MapDeserializer.deserialize(MapDeserializer.java:26)
at com.fasterxml.jackson.databind.ObjectMapper._readMapAndClose(ObjectMapper.java:3789)
at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:2872)

I have tried searching over stackoverflow but couldnot find a matchable solution to this type of JSON.

Any help would be appreciated.

NOTE: This JSON mentioned here is different a JSON without Key , for the first element it has value directly and inside that value it has key:valuepair. I am not sure how do I access key:value pair which is inside a value.

Vikrant Kashyap

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.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Java

com.fasterxml.jackson.databind.exc.MismatchedInputException: Can not deserialize instance of object out of START_ARRAY token - JAVA

From Java

Jackson error: Cannot deserialize instance of `java.lang.String` out of START_ARRAY token

From Java

Can not deserialize instance of java.util.ArrayList out of START_OBJECT token

From Dev

Json Mapping Exception can not deserialize instance out of START_ARRAY token

From Dev

Cannot deserialize instance of object out of START_ARRAY token in Spring Webservice

From Dev

Exception: "org.codehaus.jackson.map.JsonMappingException: Can not deserialize instance of java.lang.String out of START_OBJECT token"

From Dev

Can not deserialize instance of JsonGen out of START_ARRAY token : newbee

From Dev

Can not deserialize instance of java.util.List out of VALUE_STRING

From Dev

com.fasterxml.jackson.databind.JsonMappingException: Can not deserialize instance of org.springframework.data.domain.Sort out of START_ARRAY token

From Dev

JSON deserialization throwing exception - Can not deserialize instance of java.util.ArrayList out of START_OBJECT token

From Dev

com.fasterxml.jackson.databind.JsonMappingException: Can not deserialize out of START_ARRAY token

From Dev

Can not deserialize instance of Object out of START_ARRAY token

From Dev

Ignore the "Can not deserialize instance of java.util.LinkedHashMap out of START_ARRAY token" error

From Dev

JsonMappingException: Can not deserialize instance of java.lang.Integer out of START_OBJECT token

From Dev

Java REST API: Can not deserialize instance of Object out of START_ARRAY token

From Dev

Exception: Can not deserialize instance of java.util.ArrayList out of START_OBJECT token at

From Dev

com.fasterxml.jackson.databind.exc.MismatchedInputException: Can not deserialize instance of object out of START_ARRAY token

From Dev

JsonMappingException: Can not deserialize instance of java.lang.Integer out of START_OBJECT token

From Dev

Convert JSON to Object throws JsonMappingException "Can not deserialize instance of class out of START_ARRAY token"

From Dev

com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot deserialize instance of Object out of START_ARRAY token

From Dev

Can not serialize instance of class out of START_ARRAY token\n

From Dev

ObjectMapper fails to deserialize - cannot deserialize instance of .... out of START_ARRAY token

From Dev

JsonMappingException: Can not deserialize instance of java.util.List out of START_OBJECT token

From Dev

Can not deserialize instance of Object out of START_ARRAY token

From Dev

jsonMappingException org.codehaus.jackson.map.JsonMappingException: Can not deserialize instance of java.util.ArrayList out of START_OBJECT token at

From Dev

Java REST API: Can not deserialize instance of Object out of START_ARRAY token

From Dev

Can not deserialize instance of my package out of START_ARRAY token

From Dev

Can not deserialize instance of SaleListDTO out of START_ARRAY token

From Dev

Jackson Can not deserialize instance of java.util.ArrayList out of VALUE_STRING token

Related Related

  1. 1

    com.fasterxml.jackson.databind.exc.MismatchedInputException: Can not deserialize instance of object out of START_ARRAY token - JAVA

  2. 2

    Jackson error: Cannot deserialize instance of `java.lang.String` out of START_ARRAY token

  3. 3

    Can not deserialize instance of java.util.ArrayList out of START_OBJECT token

  4. 4

    Json Mapping Exception can not deserialize instance out of START_ARRAY token

  5. 5

    Cannot deserialize instance of object out of START_ARRAY token in Spring Webservice

  6. 6

    Exception: "org.codehaus.jackson.map.JsonMappingException: Can not deserialize instance of java.lang.String out of START_OBJECT token"

  7. 7

    Can not deserialize instance of JsonGen out of START_ARRAY token : newbee

  8. 8

    Can not deserialize instance of java.util.List out of VALUE_STRING

  9. 9

    com.fasterxml.jackson.databind.JsonMappingException: Can not deserialize instance of org.springframework.data.domain.Sort out of START_ARRAY token

  10. 10

    JSON deserialization throwing exception - Can not deserialize instance of java.util.ArrayList out of START_OBJECT token

  11. 11

    com.fasterxml.jackson.databind.JsonMappingException: Can not deserialize out of START_ARRAY token

  12. 12

    Can not deserialize instance of Object out of START_ARRAY token

  13. 13

    Ignore the "Can not deserialize instance of java.util.LinkedHashMap out of START_ARRAY token" error

  14. 14

    JsonMappingException: Can not deserialize instance of java.lang.Integer out of START_OBJECT token

  15. 15

    Java REST API: Can not deserialize instance of Object out of START_ARRAY token

  16. 16

    Exception: Can not deserialize instance of java.util.ArrayList out of START_OBJECT token at

  17. 17

    com.fasterxml.jackson.databind.exc.MismatchedInputException: Can not deserialize instance of object out of START_ARRAY token

  18. 18

    JsonMappingException: Can not deserialize instance of java.lang.Integer out of START_OBJECT token

  19. 19

    Convert JSON to Object throws JsonMappingException "Can not deserialize instance of class out of START_ARRAY token"

  20. 20

    com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot deserialize instance of Object out of START_ARRAY token

  21. 21

    Can not serialize instance of class out of START_ARRAY token\n

  22. 22

    ObjectMapper fails to deserialize - cannot deserialize instance of .... out of START_ARRAY token

  23. 23

    JsonMappingException: Can not deserialize instance of java.util.List out of START_OBJECT token

  24. 24

    Can not deserialize instance of Object out of START_ARRAY token

  25. 25

    jsonMappingException org.codehaus.jackson.map.JsonMappingException: Can not deserialize instance of java.util.ArrayList out of START_OBJECT token at

  26. 26

    Java REST API: Can not deserialize instance of Object out of START_ARRAY token

  27. 27

    Can not deserialize instance of my package out of START_ARRAY token

  28. 28

    Can not deserialize instance of SaleListDTO out of START_ARRAY token

  29. 29

    Jackson Can not deserialize instance of java.util.ArrayList out of VALUE_STRING token

HotTag

Archive