I want to parsing json object like this:
{
"Count" : 1,
"Data" : [
{
"ContactID" : 1567993182,
"Email" : "enamdimensi@localhost.com",
"Action" : "unsub",
"Name" : "",
"Properties" : {}
}
],
"Total" : 1
}
to this java object.
public class Response {
@JsonProperty("Status")
private String status;
@JsonProperty("Data")
private List<DataResponse> data;
@JsonProperty("Total")
private Integer total;
@JsonProperty("Count")
private Integer count;
public MailjetResponse() {
super();
}
........ setter and getter .......
}
class DataResponse {
@JsonProperty("ContactID")
private String contactId;
@JsonProperty("Name")
private String name;
@JsonProperty("Email")
private String email;
@JsonProperty("Action")
private String action;
@JsonProperty("Properties")
private Map<String, Object> properties;
public DataResponse() {
super();
}
....... setter and getter .....
}
I used Jackson to do that, and this is my code:
final ObjectMapper mapper = new ObjectMapper();
MailjetResponse response = mapper.readValue(content, Response.class);
But, if I debug the response, all of the fields Response is null.
response [Status=null, Data=null, Total=null, Count=null]
is there something wrong with my code ?
UPDATED CODE: Response class
public class Response {
@JsonProperty("Status")
private String status;
@JsonProperty("Data")
private List<DataResponse> data;
@JsonProperty("Total")
private Integer total;
@JsonProperty("Count")
private Integer count;
public String getStatus() {
return status;
}
public void setStatus(String status) {
this.status = status;
}
public Integer getTotal() {
return total;
}
public void setTotal(Integer total) {
this.total = total;
}
public Integer getCount() {
return count;
}
public void setCount(Integer count) {
this.count = count;
}
@Override
public String toString() {
return "MailjetResponse [status=" + status + ", data=" + data
+ ", total=" + total + ", count=" + count + "]";
}
}
DataResponse class
public class DataResponse {
@JsonProperty("ContactID")
private String contactId;
@JsonProperty("Name")
private String name;
@JsonProperty("Email")
private String email;
@JsonProperty("Action")
private String action;
@JsonProperty("Properties")
private Map<String, Object> properties;
public String getContactID() {
return contactId;
}
public void setContactID(String contactID) {
contactId = contactID;
}
public String getName() {
return name;
}
public void setName(String name) {
name = name;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
email = email;
}
public String getAction() {
return action;
}
public void setAction(String action) {
action = action;
}
@Override
public String toString() {
return "DataResponse [contactId=" + contactId + ", name=" + name
+ ", email=" + email + ", action=" + action + ", properties="
+ properties + "]";
}
}
There result bocome like this:
response MailjetResponse [status=null, data=[DataResponse [contactId=1567993182, name=null, email=null, action=null, properties={}]], total=1, count=1]