tag:blogger.com,1999:blog-596010276983280240.post3866905390999249379..comments2024-03-03T00:35:48.873-08:00Comments on FreshByte Labs: Using custom gson converter to parse dynamic json with free source codeNavneet Krishnahttp://www.blogger.com/profile/15189580182919776285noreply@blogger.comBlogger2125tag:blogger.com,1999:blog-596010276983280240.post-54712575975175407652020-02-06T03:16:55.064-08:002020-02-06T03:16:55.064-08:00Well, this statement >> Cars a = g.fromJson(...Well, this statement >> Cars a = g.fromJson(arg0, Cars.class); here has no use here, i might have added it by mistake. The reason it doesn't throw "Expected BEGIN_ARRAY but was BEGIN_OBJECT" is that the json contains an object as expected from our code, but the json has different field names as compared to our code("cars"), since gson cant find this variable, it just sets the attributes as null at first and later fills in the list. You may just replace this line >> Cars a = g.fromJson(arg0, Cars.class); with this one >> Cars a =new Cars(); . This will correctly fill your List with carsNavneet Krishnahttps://www.blogger.com/profile/15189580182919776285noreply@blogger.comtag:blogger.com,1999:blog-596010276983280240.post-7531492007116641372020-02-05T04:14:11.869-08:002020-02-05T04:14:11.869-08:00Hello,
First thank you very much for this post!! I...Hello,<br />First thank you very much for this post!! It helped me a lot.<br />Second I have a question:<br />How is it possible that I can call "Cars a = g.fromJson(arg0, Cars.class);" in deserialize method and that this method does not throw "IllegalStateException: Expected BEGIN_ARRAY but was BEGIN_OBJECT" ..?Vitahttps://www.blogger.com/profile/16303311925061313022noreply@blogger.com