android - JAVA Jackson Parsing JSON Response that Contains List/Array -
i'm trying deserialize json string keep running json mapping exception. i've been scouring internet have had little luck.
my json response i'm trying deserialize looks following:
{ "comments": [{ "id": "fa6491aeb", "user": { "userid": "e4dddf5e1", "username": "userx", "name": "userx", "profilephotouri": "" }, "message": "8: 23 - userx", "timestamp": 1429844781919 },{ "id": "ed3e71", "user": { "userid": "20b8f1", "username": "userw", "name": "userw", "profilephotouri": "" }, "message": "8: 22 - userw", "timestamp": 1429844780250 }, //... more items ], "cancallercomment": true }
here abridged version of error get:
com.fasterxml.jackson.databind.jsonmappingexception: can not deserialize instance of com.test.android.commentsresponse out of start_array token @ [source: [{"user":{"userid":"fa6491aeb", ..........]; line: 1, column: 1] @ com.fasterxml.jackson.databind.deserializationcontext.mappingexception(deserializationcontext.java:835) @ com.fasterxml.jackson.databind.deserializationcontext.mappingexception(deserializationcontext.java:831) @ com.fasterxml.jackson.databind.deser.beandeserializerbase.deserializefromarray(beandeserializerbase.java:1220) @ com.fasterxml.jackson.databind.deser.beandeserializer._deserializeother(beandeserializer.java:165) ...
i tried wrapping response mentioned in this post, still same error. call stack-trace, seems likes has list<comment>. i.e, need pass list object. objectmapper.readvalue(json, commentresponse.class) not sufficient?
my java classes defined follows:
public class comment { private string id; private user user; private string message; private long timestamp; // getter/setters } public class commentresponse { list<comment> comments; boolean cancallercomment = false; // getter/setters }
if helps, i'm using jackson version 2.5.3; , targeted platform android.
edit: sparks solution below correct. had typo trying parse json wrong web service.
your json malformed. can see error message:
[source: [{"user":{"userid":"fa6491aeb", ..........];
it seems parser has encountered array instead of object.
Comments
Post a Comment