0

I'm getting this error when deserialzing json to an ArrayList

12-31 05:29:10.963: W/System.err(2939): org.codehaus.jackson.map.JsonMappingException: Can not deserialize instance of java.util.ArrayList out of VALUE_TRUE token

here's the structure of the json:

{
"c_Evenement" : [{
        "id" : {
            "o_id" : 9,
            "t_id" : 1,
            "key" : "1_9"
        },
        "bla1" : "bla bla bla bla",
        "bla2" : "bla bla bla bla",
        "bla3" : "bla bla bla bla",
        "bla4" : "bla bla bla bla"
    }
],
"themes" : [{
        "id" : 1,
        "nom" : "Administration"
    }
    ],
"c_Theme" : [{
        "id" : {
            "couche_id" : 761,
            "theme_id" : 1,
            "key" : "1_761"
        },
        "layerId" : 0
    }
],
"message" : null,
"ok" : true
}

here's the LireTheme class :

@JsonIgnoreProperties(ignoreUnknown=true)
public class LireTheme {

private Themes themes;
private CouchesTheme c_Theme;
private ClassesEvenement c_Evenement;

private String message;
private boolean ok;

//getters and setters

}

here's the LireTheme class that is simply a mapping HashMap :

public class LireThemes extends HashMap<String, ArrayList<LireTheme>> {
    private static final long serialVersionUID = 1L;
}

and here's how i deserialize it :

LireThemes lirethemes = null;
ArrayList<LireTheme> themeList = null;
final InputStream stream = context.getAssets().open("lireThemes.json");
lirethemes = objectMapper.readValue(stream, LireThemes.class);
themeList = lirethemes.get("themes");

i really need help please.

4
  • I think the issue JacksonMapper is having is that it doesn't know how to deserialize the attributes c_Evenement and c_Theme, because in the class they contain different names. Try using always the same name, is that possible? Commented Dec 31, 2014 at 11:15
  • the properties and classes have the same names in json. it's only the LireTheme class who doesn't have an attribute in json and i put @JsonIgnoreProperties(ignoreUnknown=true) to ignore it Commented Dec 31, 2014 at 11:24
  • Now the json it's not valid, maybe while updating something went wrong :/ Parse error on line 19: ...istration" }"c_Theme": [ ----------------------^ Expecting 'EOF', '}', ',', ']' Commented Dec 31, 2014 at 11:28
  • sorry facundofarias i just forget "]," before "c_Theme" but this is not the real json i've just created this one to show the architecture Commented Dec 31, 2014 at 11:32

1 Answer 1

3

Right, so now I can see that each one of those attributes are collections, not simple attributes. So for each one of those, Jackson it's trying to map to a List, for example. So, try with:

@JsonIgnoreProperties(ignoreUnknown=true)
public class LireTheme {

private List<Themes> themes;
private List<CouchesTheme> c_Theme;
private List<ClassesEvenement> c_Evenement;

private String message;
private boolean ok;

//getters and setters

}

Hope this helps!

Sign up to request clarification or add additional context in comments.

1 Comment

actually you showed me another error :-) but thank you this helps me alot

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.