Json Mapping Exception can not deserialize instance out of START_ARRAY token

Marcin Erbel

I'm trying to parse my json request to my model. I dunno what is wrong in this code. Syntax of json looks correct and annotations on Java model also. I don't know why I'm getting error like:

Caused by: org.codehaus.jackson.map.JsonMappingException: Can not deserialize instance of ParametersType out of START_ARRAY token
(through reference chain: Document["parameters"])

Java model:

@JsonIgnoreProperties( ignoreUnknown = true )
public class Document {

   @XmlElement( required = true )
   @JsonProperty( "templateId" )
   protected String templateId;

   @JsonProperty( "parameters" )
   @XmlElement( required = true )
   protected ParametersType parameters;

   @JsonProperty( "documentFormat" )
   @XmlElement( required = true )
   protected DocumentFormatType documentFormat;

...}

@JsonIgnoreProperties( ignoreUnknown = true )
public class ParametersType {

    @JsonProperty( "parameter" )
    protected List<ParameterType> parameter;

...}

@JsonIgnoreProperties( ignoreUnknown = true )
public class ParameterType {

    @XmlElement( required = true )
    @JsonProperty( "key" )
    protected String key;

    @XmlElement( required = true )
    @JsonProperty( "value" )
    @XmlSchemaType( name = "anySimpleType" )
    protected Object value;

    @JsonProperty( "type" )
    @XmlElement( required = true, defaultValue = "STRING_TYPE" )
    protected ParamType type;

....}

Json code:

{
    "templateId": "123",
    "parameters": [
        {
            "parameter": [
                {
                    "key": "id",
                    "value": "1",
                    "type": "STRING_TYPE"
                },
                {
                    "key": "id2",
                    "value": "12",
                    "type": "STRING_TYPE"
                }
            ]
        }
    ],
    "documentFormat": "PDF"
}
gregwhitaker

You have declared parameters as a single object, but you are returning it as an array of multiple objects in your JSON document.

Your model currently defines the parameters node as a ParametersType object:

@JsonProperty( "parameters" )
@XmlElement( required = true )
protected ParametersType parameters;

This means your model object is expecting a JSON document that looks like the following:

{
    "templateId": "123",
    "parameters": {
            "parameter": [
                {
                    "key": "id",
                    "value": "1",
                    "type": "STRING_TYPE"
                },
                {
                    "key": "id2",
                    "value": "12",
                    "type": "STRING_TYPE"
                }
            ]
        },
    "documentFormat": "PDF"
}

But in your JSON document you are returning an array of ParametersType objects. So you need to change your model to be a list of ParametersType objects:

@JsonProperty( "parameters" )
@XmlElement( required = true )
protected List<ParametersType> parameters;

The fact that you are returning an array of ParametersType objects is why the parser is complaining about not being able to deserialize an object out of START_ARRAY. It was looking for a node with a single object, but found an array of objects in your JSON.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

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

From Dev

Can not deserialize instance of Object out of START_ARRAY token

From Dev

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

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

From Dev

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

From Dev

Java REST API: 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

com.fasterxml.jackson.databind.exc.MismatchedInputException: 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

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

From Java

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

From Dev

com.fasterxml.jackson.databind.JsonMappingException: Can not deserialize instance of org.springframework.data.domain.Sort 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 Java

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

From Dev

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

From Dev

com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot 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.JsonMappingException: Can not deserialize 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

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

From Java

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

From Dev

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

From Dev

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

From Dev

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

From Dev

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

From Java

JsonMappingException: out of START_ARRAY token

Related Related

  1. 1

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

  2. 2

    Can not deserialize instance of Object out of START_ARRAY token

  3. 3

    Can not deserialize instance of Object out of START_ARRAY token

  4. 4

    Can not deserialize instance of my package out of START_ARRAY token

  5. 5

    Can not deserialize instance of SaleListDTO out of START_ARRAY token

  6. 6

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

  7. 7

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

  8. 8

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

  9. 9

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

  10. 10

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

  11. 11

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

  12. 12

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

  13. 13

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

  14. 14

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

  15. 15

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

  16. 16

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

  17. 17

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

  18. 18

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

  19. 19

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

  20. 20

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

  21. 21

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

  22. 22

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

  23. 23

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

  24. 24

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

  25. 25

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

  26. 26

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

  27. 27

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

  28. 28

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

  29. 29

    JsonMappingException: out of START_ARRAY token

HotTag

Archive