android - Retrofit parse empy array [] -
i need parse list of object, whith can emply. {"data":[]}
use tamplated callback callback<t>
called with
public static datalist { public list<data> data }; api.getdata(new callback<datalist>() {...});
it crashed error:java.lang.classcastexception: com.google.gson.internal.linkedtreemap cannot cast com...datalist
please help
your model should work fine. perhaps server isn't returning think does, or maybe not application/json
it's returning?
here's quick demo:
doing on url http://www.mocky.io/v2/5583c7fe2dda051e04bc699a return following json:
{ data: [ ] }
if run following class, you'll see works fine:
public class retrofitdemo { interface api { @get("/5583c7fe2dda051e04bc699a") void getdatalist(callback<datalist> cb); } static class datalist { list<data> data; } static class data { } public static void main(string[] args) { api api = new restadapter.builder() .setendpoint("http://www.mocky.io/v2") .build() .create(api.class); api.getdatalist(new callback<datalist>() { @override public void success(datalist datalist, response response) { system.out.println("datalist=" + datalist); } @override public void failure(retrofiterror retrofiterror) { throw retrofiterror; } }); } }
Comments
Post a Comment