Exception java.util.LinkedHashMap ne peut pas être lancé à java.util.Liste

Tout en travaillant autour de code suivant, j'ai obtenu l'exception mentionnée ci-dessous.

List<Map<String, Object>> obj = mapper.readValue(result.getBody(), new TypeReference<Map<String,Object>>(){});

for (Map<String, Object> map : obj) {
    for(Map.Entry<String, Object> entry : map.entrySet()){
        System.out.println("Key : "+entry.getKey()+" Value is: "+entry.getValue());
    }
}

Stacktrace: java.lang.ClassCastException: java.util.LinkedHashMap cannot be cast to java.util.List

  • La ligne est en train de jeter de l'exception? Le premier? Avez-vous essayé de remplacer new TypeReference<Map<String,Object>>(){} avec new TypeReference<List<Map<String,Object>>>(){}?
  • Oui je l'ai essayé et je suis arriver exception de dire: ne Peut pas désérialiser instance de java.util.Liste de tableaux de START_OBJECT jeton à [Source: {"total":1,"films":[{"id":"771390242","title":"Deadpool"}]
  • Utilisation Map<String, Object> obj = mapper.readValue(result.getBody(), new TypeReference<Map<String,Object>>(){});
  • avez-vous été en mesure de résoudre ce problème?
InformationsquelleAutor Vamsi | 2016-02-23