android - Is retrofit supports keypath in json parsing or how to to this? -


for example have json looks like:

{     "data": [         {             "name": "one"         },         {             "name": "two"         }     ] } 

for example have object user field name.

is possible write method parse data array objects user?

something

call<list<user>> getusers(@keypath("data")) 

now this, need create wrapper class like

public class userswrapper { @serializename("data") public arraylist users; }

and in service next

public interface service {  @get("users")   call<userswrapper> getusers() } 

but requests response data variable objects in array.

in case need create wrappers data requests. pain :(

?

i'd way:

global class wrapper<t> parse whole json

public class wrapper<t> {     public list<t> data; } 

and user parse actual array;

public class user {     public string name; } 

then, api interface:

@get("/people") wrapper<user> getusers(); 

and in datasource class this:

@override public list<user> getusers() {     wrapper<user> userswrapper = myapiinterface.getusers();     return userswrapper.data; } 

upd1:
solution create custom jsondeserializer (like described here) list<user> type, register registertypeadapter custom gson object , can deserialise json directly list<user>. though, solution brings more code , potential benefit unclear me.


Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

javascript - Get parameter of GET request -

javascript - Twitter Bootstrap - how to add some more margin between tooltip popup and element -