java - POJO for this complex JSON -
i'm new pojos , working on creating objects represent json google apis. how can create pojo json?
"notificationsettings": { "notifications": [ { "type": "eventcreation", "method": "email" }, { "type": "eventchange", "method": "email" }, { "type": "eventcancellation", "method": "email" }, { "type": "eventresponse", "method": "email" } ] } i have rest of json figured out, however, gson.fromjson() keeps returning null.
edit 1
this have
private static class notificationsettings{ public notificationsettings(){ } public notificationsettings(map<string, list<notification>> notifications) { super(); this.setnotifications(notifications); } public map<string, list<notification>> getnotifications() { homecoming notifications; } public void setnotifications(map<string, list<notification>> notifications) { this.notifications = notifications; } private map<string, list<notification>> notifications; } private static class notification{ public notification(){ } public notification(string type, string method) { super(); this.type = type; this.method = method; } private string type; private string method; /** * @return type */ public string gettype() { homecoming type; } /** * @param type type set */ public void settype(string type) { this.type = type; } /** * @return method */ public string getmethod() { homecoming method; } /** * @param method method set */ public void setmethod(string method) { this.method = method; } } edit 2 question, constructors arguments required? in addition, tostring() method required well?
thanks!
a pojo plain old java object, class fields , getters/setters. don't think works java new pojos unless learning java. why won't give exact class structure, otherwise doing job.
you need define type elements in json string. let's review string , how can map it:
"notificationsettings": { //name of class: notificationsettings "notifications": [ //array of notification objects. means need notification class //and array or list field called notification in notificationsettings class { //this defines construction notification class "type": "eventcreation", //string field called type "method": "email" //string field called method }, { "type": "eventchange", "method": "email" }, { "type": "eventcancellation", "method": "email" }, { "type": "eventresponse", "method": "email" } ] } from implementation, looks should replace private map<string, list<notification>> notifications; field private list<notification> notifications; , create notification class top class in own file.
java json gson google-calendar pojo
No comments:
Post a Comment