I have no error message but the parsing simply doesn’t seem to work.
Here’s the compact JSON response :
My “WPPost” has a problem :
public class WPPost {
int id;
String title;
String content;
ArrayList<WPPostAttachment> attachments;
WPPostCustomFields custom_fields;
public String getContent() {
return content;
}
public String getTitle() {
return title;
}
public int getId() {
return id;
}
public ArrayList<WPPostAttachment> getAttachments() {
return attachments;
}
public WPPostCustomFields getCustomFields() {
return custom_fields; //Problem here
}
}
The WPPostAttachement getter works well but its structure is different to the custom field structure.
public class WPPostAttachment {
String id;
String url;
String title;
public String getId() {
return id;
}
public String getUrl() {
return url;
}
public String getTitle() {
return title;
}
}
public class WPPostCustomFields {
String address;
public String getAddress() {
return address;
}
}
How should I change the WPPost class to make the parsing work ?
You can use this online tool to convert your json object to POJO(Plain Old Java Object) type.
Copy paste your json and set Source type: JSON and Annotation style: GSON. Change the package and class name the way you like. Hope this helps. If you are still unable to get the proper POJO, you can give me your json object in text format and i’ll convert it to POJO. Thanks.