com.fasterxml.jackson.databind.JsonMappingException: Can not deserialize instance of java.lang.String out of START_OBJECT token

1

I'm trying to map a JSON to an object in java, the JSON is something like this:

{
    "usage": {
        "text_characters": 22,
        "features": 1,
        "text_units": 1
    },
    "entities": [{
        "count": 1,
        "text": "pisos",
        "disambiguation": {
            "subtype": ["NONE"]
        },
        "type": "Producto"
    }, {
        "count": 1,
        "text": "No hay",
        "disambiguation": {
            "subtype": ["NONE"]
        },
        "type": "Quiebre_Stock"
    }, {
        "count": 1,
        "text": "madera",
        "disambiguation": {
            "subtype": ["NONE"]
        },
        "type": "Producto"
    }],
    "language": "es"
}

I'm trying to map the JSON with this method

parsedJsonObj = mapper.readValue(result, NLUEntitiesRelations.class);

and NLUEntitiesRelations.class is like that

public class NLUEntitiesRelations {
    private UsageNLU usage;
    private List<EntityNLU> entities;
    private String language;

    //getter and setter
}

public class UsageNLU {
    private int text_characters;
    private int features;
    private int text_units;
    //getersand setter
}

public class EntityNLU {
    private int count;
    private String text;
    private DisambiguationNLU disambiguation;
    private String type;
    //getter and setter
}

public class DisambiguationNLU {
    private List<String> subtype;
    //getter and setter
}

but when I run this, I get the following error, and create the new classes for the JSON within the JSON

  

Error: com.fasterxml.jackson.databind.JsonMappingException: Can not   deserialize instance of java.lang.String out of START_OBJECT token at   [Source: {"usage": {"text_units": 1, "text_characters": 22,   "features": 1}, "language": "is", "entities": [{"type": "Product",   "text": "floors", "disambiguation": {"subtype": ["NONE"]}, "count":   1}, {"type": "Quiebre_Stock", "text": "no hay", "disambiguation": {   "subtype": ["NONE"]}, "count": 1}, {"type": "Product", "text":   "wood", "disambiguation": {"subtype": ["NONE"]}, "count": 1}]   }; line: 2, column: 12] (through reference chain:   cl.sodimac.watson.alchemy.json.NLUEntitiesRelations ["usage"])

    
asked by neo_free 06.05.2018 в 23:24
source

0 answers