I have been trying to find a tutorial for Moshi library in android java for parsing some complicated api but am unable to do so.... any help is appriciated ...
Api sample Value
{
"kind": "youtube#searchListResponse",
"etag": "\"XI7nbFXulYBIpL0ayR_gDh3eu1k/VZYjjnY2DRtcVQGjTcTJVE_YOvM\"",
"nextPageToken": "CAUQAA",
"regionCode": "IN",
"pageInfo": {
"totalResults": 1000000,
"resultsPerPage": 5
},
"items": [
{
"kind": "youtube#searchResult",
"etag": "\"XI7nbFXulYBIpL0ayR_gDh3eu1k/njM_Wom6sRs6l5kN528JyqirbzU\"",
"id": {
"kind": "youtube#video",
"videoId": "8-mloCL49vs"
},
"snippet": {
"publishedAt": "2018-05-11T04:00:00.000Z",
"channelId": "UCz9yS18zJGQObwUL_K-ICnw",
"title": "Karol G - Mi Cama",
"description": "Music video by Karol G performing Mi Cama. © 2018 UMG Recordings, Inc. http://vevo.ly/rsmwbJ.",
"thumbnails": {
"default": {
"url": "https://i.ytimg.com/vi/8-mloCL49vs/default.jpg",
"width": 120,
"height": 90
},
"medium": {
"url": "https://i.ytimg.com/vi/8-mloCL49vs/mqdefault.jpg",
"width": 320,
"height": 180
},
"high": {
"url": "https://i.ytimg.com/vi/8-mloCL49vs/hqdefault.jpg",
"width": 480,
"height": 360
}
},
"channelTitle": "KarolGVEVO",
"liveBroadcastContent": "none"
}
}
]}
this is the code i found & was trying
Moshi moshi = new Moshi.Builder().build();
JsonAdapter<Hero> adapter = moshi.adapter(Hero.class);
Hero hero = adapter.fromJson(run(strings[0]));
i am getting app crashes & the error is
Caused by: java.lang.IllegalArgumentException: Platform java.util.ArrayList<com.example.Inside> (with no annotations) requires explicit JsonAdapter to be registered
EDIT :
i have added the code for my Hero class
public class Hero {
private List<Inside> items;
private String kind;
private String etag;
private String nextPageToken;
private String regionCode;
private PAGEINFO pageInfo;
public Hero() {
}
public Hero(List<Inside> items, String kind, String etag, String nextPageToken, String regionCode, PAGEINFO pageInfo) {
this.items = items;
this.kind = kind;
this.etag = etag;
this.nextPageToken = nextPageToken;
this.regionCode = regionCode;
this.pageInfo = pageInfo;
}
//setter getters for all elements
}
& some idea about RealmListJsonAdapter is also appreciated .
thnx in advance