My JSON
looks like follow :
"message_defaults": {
"LabResultsRequestDefaultMessage": {
"MsgTypeId": 8,
"StaffId": 122,
"StaffName": "Willis,Sam",
"FirstName": "Sam",
"MI": "D",
"LastName": "Willis",
"DefaultMessage": "Lab Department"
},
"ReferralRequestDefaultMessage": {
"MsgTypeId": 6,
"StaffId": 122,
"StaffName": "Willis,Sam",
"FirstName": "Sam",
"MI": "D",
"LastName": "Willis",
"DefaultMessage": "Physican"
},
"MessageComposeDefaultMessage": {
"MsgTypeId": 1,
"StaffId": 122,
"StaffName": "Willis,Sam",
"FirstName": "Sam",
"MI": "D",
"LastName": "Willis",
"DefaultMessage": "Office Manager/Willis Sam"
}
}
Now each elemet in message_defaluts
is having same structure (Say one POJO called MessageDefault.java). So how can I get all message defaults
as a List<MessageDefault>
??
I am using gson for parsing. Also I can't change JSON response.
EDIT ::
MessageDefault.java
public class MessageDefault{
private String defaultMessage;
private String firstName;
private String lastName;
private String mI;
private int msgTypeId;
private int staffId;
private String staffName;
public String getDefaultMessage(){
return this.defaultMessage;
}
public void setDefaultMessage(String defaultMessage){
this.defaultMessage = defaultMessage;
}
public String getFirstName(){
return this.firstName;
}
public void setFirstName(String firstName){
this.firstName = firstName;
}
public String getLastName(){
return this.lastName;
}
public void setLastName(String lastName){
this.lastName = lastName;
}
public String getMI(){
return this.mI;
}
public void setMI(String mI){
this.mI = mI;
}
public int getMsgTypeId(){
return this.msgTypeId;
}
public void setMsgTypeId(int msgTypeId){
this.msgTypeId = msgTypeId;
}
public int getStaffId(){
return this.staffId;
}
public void setStaffId(int staffId){
this.staffId = staffId;
}
public String getStaffName(){
return this.staffName;
}
public void setStaffName(String staffName){
this.staffName = staffName;
}
}
Its is just structure of all message_defualts
. But In JSON, each child of message_defualts
is having different name like LabResultsRequestDefaultMessage, ReferralRequestDefaultMessage etc
which are being reflected in POJO MessageDefault.java. But from JSON I want List of them.
Thanks.
You can do the following without changing your json structure.
If you want to get List from json first you have to correct your json. List must be in '[ ]'.
EDIT : try this for converting to list
Follow this link