android - GSON and Google Drive Java API - “Expected BEGIN_OBJECT but was BEGIN_ARRAY”? -


i trying serialize , deserialize filelist object using gson. classes can found here:

https://developers.google.com/resources/api-libraries/documentation/drive/v2/java/latest/com/google/api/services/drive/model/filelist.html

and

https://developers.google.com/resources/api-libraries/documentation/drive/v2/java/latest/com/google/api/services/drive/model/file.html

this how i'm doing it:

private list<file> mlistofresults = new arraylist<file>();  filelist filelist = new filelist(); filelist.setitems(mlistofresults); outstate.putstring("result_list", new gson().tojson(filelist)); 

and how i'm trying unserialize it:

type collectiontype = new typetoken<filelist>(){}.gettype(); filelist filelist = new gson().fromjson(savedinstancestate.getstring("result_list"), collectiontype); 

here's json:

{ "items": [ {   "alternatelink": "censoredlink",   "appdatacontents": false,   "copyable": true,   "createddate": {     "value": 1414937347638,     "tzshift": 0,     "dateonly": false   },   "downloadurl": "censoredurl",   "editable": true,   "etag": "\"m4lmw\"",   "fileextension": "png",   "filesize": 982646,   "headrevisionid": "0bpq",   "iconlink": "url",   "id": "0bxww1fyle",   "imagemediametadata": {     "height": 1920,     "width": 1200   },   "kind": "drive#file",   "labels": {     "hidden": false,     "restricted": false,     "starred": false,     "trashed": false,     "viewed": true   },   "lastmodifyinguser": {     "displayname": "myname",     "emailaddress": "myemail",     "isauthenticateduser": true,     "kind": "drive#user",     "permissionid": "myid"   },   "lastmodifyingusername": "myname",   "lastviewedbymedate": {     "value": 1415793202783,     "tzshift": 0,     "dateonly": false   },   "markedviewedbymedate": {     "value": 1414937361409,     "tzshift": 0,     "dateonly": false   },   "md5checksum": "mymd5checksum",   "mimetype": "image\/png",   "modifiedbymedate": {     "value": 1415793202783,     "tzshift": 0,     "dateonly": false   },   "modifieddate": {     "value": 1415793202783,     "tzshift": 0,     "dateonly": false   },   "originalfilename": "screenshot_2014-11-02-16-07-03.png",   "ownernames": [     "myname"   ],   "owners": [     {       "displayname": "myname",       "emailaddress": "myemail",       "isauthenticateduser": true,       "kind": "drive#user",       "permissionid": "myid"     }   ],   "parents": [     {       "id": "parentid",       "isroot": true,       "kind": "drive#parentreference",       "parentlink": "parentlink",       "selflink": "myselflink"     }   ],   "quotabytesused": 982646,   "selflink": "link",   "shared": false,   "thumbnaillink": "link",   "title": "screenshot_2014-11-02-16-07-03.png",   "userpermission": {     "etag": "\"m4l5r3cu\"",     "id": "me",     "kind": "drive#permission",     "role": "owner",     "selflink": "mylink",     "type": "user"   },   "version": 20986,   "webcontentlink": "mywebcontentlink",   "writerscanshare": true }, {   "alternatelink": "myalternatelink",   "appdatacontents": false,   "copyable": true,   "createddate": {     "value": 1412844742040,     "tzshift": 0,     "dateonly": false   },   "downloadurl": "mydownloadurl",   "editable": true,   "etag": "\"mdc0mq\"",   "fileextension": "png",   "filesize": 743314,   "headrevisionid": "0bx",   "iconlink": "mylink",   "id": "myid",   "imagemediametadata": {     "height": 814,     "width": 609   },   "kind": "drive#file",   "labels": {     "hidden": false,     "restricted": false,     "starred": false,     "trashed": false,     "viewed": true   },   "lastmodifyinguser": {     "displayname": "myname",     "emailaddress": "myemail",     "isauthenticateduser": true,     "kind": "drive#user",     "permissionid": "02323"   },   "lastmodifyingusername": "myname",   "lastviewedbymedate": {     "value": 1415605118741,     "tzshift": 0,     "dateonly": false   },   "markedviewedbymedate": {     "value": 1412844842132,     "tzshift": 0,     "dateonly": false   },   "md5checksum": "23123",   "mimetype": "image\/png",   "modifiedbymedate": {     "value": 1415605118741,     "tzshift": 0,     "dateonly": false   },   "modifieddate": {     "value": 1415605118741,     "tzshift": 0,     "dateonly": false   },   "originalfilename": "puasdgessy.png",   "ownernames": [     "myname"   ],   "owners": [     {       "displayname": "myname",       "emailaddress": "myemail",       "isauthenticateduser": true,       "kind": "drive#user",       "permissionid": "23123"     }   ],   "parents": [     {       "id": "parentid",       "isroot": true,       "kind": "drive#parentreference",       "parentlink": "myparentlink",       "selflink": "myselflink"     }   ],   "quotabytesused": 743314,   "selflink": "myselflink",   "shared": false,   "thumbnaillink": "mythumbnaillink",   "title": "asd.png",   "userpermission": {     "etag": "\"m-7e\"",     "id": "me",     "kind": "drive#permission",     "role": "owner",     "selflink": "mylink",     "type": "user"   },   "version": 20928,   "webcontentlink": "mylink,   "writerscanshare": true }, {   "alternatelink": "myalternatelink",   "appdatacontents": false,   "copyable": true,   "createddate": {     "value": 1414836963515,     "tzshift": 0,     "dateonly": false   },   "downloadurl": "mydownloadurl",   "editable": true,   "etag": "\"m4ma\"",   "fileextension": "png",   "filesize": 48876,   "headrevisionid": "myid",   "iconlink": "myicon",   "id": "myid",   "imagemediametadata": {     "height": 1920,     "width": 1200   },   "kind": "drive#file",   "labels": {     "hidden": false,     "restricted": false,     "starred": false,     "trashed": false,     "viewed": true   },   "lastmodifyinguser": {     "displayname": "myname",     "emailaddress": "myemail",     "isauthenticateduser": true,     "kind": "drive#user",     "permissionid": "061"   },   "lastmodifyingusername": "myname",   "lastviewedbymedate": {     "value": 1415605116280,     "tzshift": 0,     "dateonly": false   },   "markedviewedbymedate": {     "value": 1414937348615,     "tzshift": 0,     "dateonly": false   },   "md5checksum": "e29d",   "mimetype": "image\/png",   "modifiedbymedate": {     "value": 1415605116280,     "tzshift": 0,     "dateonly": false   },   "modifieddate": {     "value": 1415605116280,     "tzshift": 0,     "dateonly": false   },   "originalfilename": "screenshot_2014-11-01-12-15-27.png",   "ownernames": [     "myname"   ],   "owners": [     {       "displayname": "myname",       "emailaddress": "myemail",       "isauthenticateduser": true,       "kind": "drive#user",       "permissionid": "mypermissionid"     }   ],   "parents": [     {       "id": "myid",       "isroot": true,       "kind": "drive#parentreference",       "parentlink": "myparentlink",       "selflink": "myselflink"     }   ],   "quotabytesused": 48876,   "selflink": "myselflink",   "shared": false,   "thumbnaillink": "mythumbnaillink",   "title": "scree5-27.png",   "userpermission": {     "etag": "\"m4rzpxxu\"",     "id": "me",     "kind": "drive#permission",     "role": "owner",     "selflink": "mylink",     "type": "user"   },   "version": 20927,   "webcontentlink": "mywebcontentlink",   "writerscanshare": true     }    ] } 

i use this, i've been stuck problem 2-3 weeks school colleague.


edit: managed serialize , deserialize filelist object, new problem occurs when try specific file deserialized filelist. serialisation works if don't add filelist's items list. below error i'm receiving.

caused by: java.lang.classcastexception: java.util.linkedhashmap cannot cast com.google.api.services.drive.model.file 

thanks lot time.


Comments

Popular posts from this blog

c++ - QTextObjectInterface with Qml TextEdit (QQuickTextEdit) -

javascript - angular ng-required radio button not toggling required off in firefox 33, OK in chrome -

xcode - Swift Playground - Files are not readable -