java - Retrofit: Error deserializing array with one element: "out of START_ARRAY token" -
i writing android app utilizing robospice, retrofit, , jackson 2.4.x,
here json trying deserialize coming rest service. elements in "data" array returned notification object want deserialize.
{ "data": [ { "uuid": "xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxx", "acctno": "xxxxxxxxxx", "title": "test notification", "content": "here content.", "date": "2015-03-24" } ] }
i first wrapping response in notificationresponse object:
@jsonrootname(value = "data") @jsonignoreproperties(ignoreunknown = true) public class notificationresponse { @jsonunwrapped public notification[] notifications; }
notification object looks this:
public class notification { @jsonproperty("uuid") public string uuid; @jsonproperty("acctno") public string acctno; @jsonproperty("title") public string title; @jsonproperty("content") public string content; @jsonproperty("date") public string date; }
stacktrace:
04-01 11:51:17.326 18978-19463/com.xxxxx.android e/﹕ exception occurred during request network execution :com.fasterxml.jackson.databind.jsonmappingexception: can not deserialize instance of com.xxxxx.android.model.notificationresponse out of start_array token @ [source: retrofit.exceptioncatchingtypedinput$exceptioncatchinginputstream@8b4da58; line: 1, column: 2] retrofit.retrofiterror: com.fasterxml.jackson.databind.jsonmappingexception: can not deserialize instance of com.xxxxx.android.model.notificationresponse out of start_array token @ [source: retrofit.exceptioncatchingtypedinput$exceptioncatchinginputstream@8b4da58; line: 1, column: 2] @ retrofit.restadapter$resthandler.invokerequest(restadapter.java:383) @ retrofit.restadapter$resthandler.invoke(restadapter.java:240) @ java.lang.reflect.proxy.invoke(proxy.java:397) @ $proxy15.notifications(unknown source) @ com.xxxxx.android.network.spice.notificationspicerequest.loaddatafromnetwork(notificationspicerequest.java:21) @ com.xxxxx.android.network.spice.notificationspicerequest.loaddatafromnetwork(notificationspicerequest.java:9) @ com.octo.android.robospice.request.cachedspicerequest.loaddatafromnetwork(cachedspicerequest.java:48) @ com.octo.android.robospice.request.defaultrequestrunner.processrequest(defaultrequestrunner.java:150) @ com.octo.android.robospice.request.defaultrequestrunner$1.run(defaultrequestrunner.java:217) @ java.util.concurrent.executors$runnableadapter.call(executors.java:422) @ java.util.concurrent.futuretask.run(futuretask.java:237) @ java.util.concurrent.threadpoolexecutor.runworker(threadpoolexecutor.java:1112) @ java.util.concurrent.threadpoolexecutor$worker.run(threadpoolexecutor.java:587) @ java.lang.thread.run(thread.java:818) caused by: retrofit.converter.conversionexception: com.fasterxml.jackson.databind.jsonmappingexception: can not deserialize instance of com.xxxxx.android.model.notificationresponse out of start_array token @ [source: retrofit.exceptioncatchingtypedinput$exceptioncatchinginputstream@8b4da58; line: 1, column: 2] @ retrofit.converter.jacksonconverter.frombody(jacksonconverter.java:40) @ retrofit.restadapter$resthandler.invokerequest(restadapter.java:367) at retrofit.restadapter$resthandler.invoke(restadapter.java:240) at java.lang.reflect.proxy.invoke(proxy.java:397) at $proxy15.notifications(unknown source) at com.xxxxx.android.network.spice.notificationspicerequest.loaddatafromnetwork(notificationspicerequest.java:21) at com.xxxxx.android.network.spice.notificationspicerequest.loaddatafromnetwork(notificationspicerequest.java:9) at com.octo.android.robospice.request.cachedspicerequest.loaddatafromnetwork(cachedspicerequest.java:48) at com.octo.android.robospice.request.defaultrequestrunner.processrequest(defaultrequestrunner.java:150) at com.octo.android.robospice.request.defaultrequestrunner$1.run(defaultrequestrunner.java:217) at java.util.concurrent.executors$runnableadapter.call(executors.java:422) at java.util.concurrent.futuretask.run(futuretask.java:237) at java.util.concurrent.threadpoolexecutor.runworker(threadpoolexecutor.java:1112) at java.util.concurrent.threadpoolexecutor$worker.run(threadpoolexecutor.java:587) at java.lang.thread.run(thread.java:818) caused by: com.fasterxml.jackson.databind.jsonmappingexception: can not deserialize instance of com.xxxxx.android.model.notificationresponse out of start_array token @ [source: retrofit.exceptioncatchingtypedinput$exceptioncatchinginputstream@8b4da58; line: 1, column: 2] @ com.fasterxml.jackson.databind.deserializationcontext.mappingexception(deserializationcontext.java:749) @ com.fasterxml.jackson.databind.deserializationcontext.mappingexception(deserializationcontext.java:745) @ com.fasterxml.jackson.databind.deser.beandeserializerbase.deserializefromarray(beandeserializerbase.java:1203) @ com.fasterxml.jackson.databind.deser.beandeserializer._deserializeother(beandeserializer.java:147) @ com.fasterxml.jackson.databind.deser.beandeserializer.deserialize(beandeserializer.java:126) @ com.fasterxml.jackson.databind.objectmapper._unwrapanddeserialize(objectmapper.java:3126) @ com.fasterxml.jackson.databind.objectmapper._readmapandclose(objectmapper.java:3049) @ com.fasterxml.jackson.databind.objectmapper.readvalue(objectmapper.java:2206) @ retrofit.converter.jacksonconverter.frombody(jacksonconverter.java:36) at retrofit.restadapter$resthandler.invokerequest(restadapter.java:367) at retrofit.restadapter$resthandler.invoke(restadapter.java:240) at java.lang.reflect.proxy.invoke(proxy.java:397) at $proxy15.notifications(unknown source) at com.xxxxx.android.network.spice.notificationspicerequest.loaddatafromnetwork(notificationspicerequest.java:21) at com.xxxxx.android.network.spice.notificationspicerequest.loaddatafromnetwork(notificationspicerequest.java:9) at com.octo.android.robospice.request.cachedspicerequest.loaddatafromnetwork(cachedspicerequest.java:48) at com.octo.android.robospice.request.defaultrequestrunner.processrequest(defaultrequestrunner.java:150) at com.octo.android.robospice.request.defaultrequestrunner$1.run(defaultrequestrunner.java:217) at java.util.concurrent.executors$runnableadapter.call(executors.java:422) at java.util.concurrent.futuretask.run(futuretask.java:237) at java.util.concurrent.threadpoolexecutor.runworker(threadpoolexecutor.java:1112) at java.util.concurrent.threadpoolexecutor$worker.run(threadpoolexecutor.java:587) at java.lang.thread.run(thread.java:818)
thanks in advance. let me know if need further info.
edit: forgot mention using following:
objectmapper om = new objectmapper(); om.configure(deserializationfeature.unwrap_root_value, true);
you need constructor annotated @jsoncreator in notificationresponse object this:
@jsoncreator public notificationresponse(notification[] notifications) { this.notifications = notifications; }
Comments
Post a Comment