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

Sasanka Panguluri

I have a json like this:

{
  "games": [
      {
        "id": "mhhlhlmlezgwniokgawxloi7mi",
        "from": "425364_456@localhost",
        "to": "788295_456@localhost",
        "token": "xqastwxo5zghlgjcapmq5tirae",
        "desc": "6CeF9/YEFAiUPgLaohbWt9pC7rt9PJlKE6TG6NkA4hE=",
        "timestamp": 1412806372232
      },
      {
        "id": "62jzlm64zjghna723grfyb6y64",
        "from": "425364_456@localhost",
        "to": "788295_456@localhost",
        "token": "xqastwxo5zghlgjcapmq5tirae",
        "desc": "Z/ww2XroGoIG5hrgiWsU1P8YHrv4SxiYHHoojzt9tdc=",
        "timestamp": 1412806373651
      }
    ]
}

I'm trying to deserialize it to an Object with ObjectMapper. Essentially as you can see, it is a List of games.

I have classes like these:

@JsonRootName(value="games")
public class GameJson{
    private List<Game> games;
// getters and setters

}

the Game class is here:

public class Game{
    private String id;

    private String from;

    private String to;

    private String token;

    private String desc;

    private Instant timestamp;

    // getters and setters
}

In my code, the ObjectMapper is doing this:

ObjectMapper mapper = new ObjectMapper();
mapper.configure(DeserializationFeature.UNWRAP_ROOT_VALUE, true);

GameJson json = mapper.readValue(
                       new FileInputStream(gamesFile), GameJson.class);

Then I get this error:

Can not deserialize instance of com.games.collection.GameJson out of START_ARRAY token

I am trying different ways to do this, but coming out with no luck. Can someone please help?

Thanks!

Sotirios Delimanolis

Get rid of

@JsonRootName(value="games")

That annotation identifies the annotated type as the target for the JSON object mapped to a JSON key named "games". In your case, that is a JSON array. An array cannot be deserialized into your GameJson class.

As you stated in the comments, you also need to remove the configuration that enables @JsonRootName.

mapper.configure(DeserializationFeature.UNWRAP_ROOT_VALUE, true);

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

Could not read JSON: Can not deserialize instance of hello.Country[] out of START_OBJECT 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

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

Can not deserialize instance of my.package.name.PlaceData[] out of START_OBJECT token

From Dev

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

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

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

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

Jackson ObjectMapper deserialize object with array

From Dev

Can not deserialize instance of SaleListDTO out of START_ARRAY 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

    Could not read JSON: Can not deserialize instance of hello.Country[] out of START_OBJECT token

  6. 6

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

  7. 7

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

  8. 8

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

  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

    Can not deserialize instance of my.package.name.PlaceData[] out of START_OBJECT token

  15. 15

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

  16. 16

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

  17. 17

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

  18. 18

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

  19. 19

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

  20. 20

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

  21. 21

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

  22. 22

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

  23. 23

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

  24. 24

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

  25. 25

    Can not deserialize instance of Object out of START_ARRAY token

  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

    Jackson ObjectMapper deserialize object with array

  29. 29

    Can not deserialize instance of SaleListDTO out of START_ARRAY token

HotTag

Archive