Wednesday, 15 July 2015

android - Retrofit map json variable to keyword -



android - Retrofit map json variable to keyword -

so i'm working retrofit api has variable called "public". how go getting automatically map other variables do.

example:

@get("/?filter=my_images") void getmyimages( @query("client_id") string id, @query("api_key") string key, callback<imagelist> callback ); public static class image{ int id; string name; string distribution; string slug; // can't this: boolean public; } public static class imagelist{ string status; list<image> images; }

example api results (json):

{ "status": "ok", "images": [ { "id": 1, "name": "my first snapshot", "distribution": "ubuntu", "slug": "ubuntu-12.10-x32", "public": true }, { "id": 2, "name": "automated backup", "distribution": "ubuntu" } ] }

retrofit uses gson serialization , json.

gson provides @serializedname annotation in order alter key field or method mapped. can utilize handling reserved word:

@serializedname("public") public string ispublic;

android gson retrofit

No comments:

Post a Comment