Reputation: 127
I am trying to parse json to a POJO using retrofit, but keeps getting an error. It seems to get the data and as far as I can see from the logcat i reads and parses the json correctly. But it returns succes=false and do not return a responsedata object. The error type and error message reads null. I have no idea of what is wrong and would appreciate any suggestions to solutions or how to locate the error.
Json
{
"competition_info": {
"headline": "competition",
"description": "description for competition.",
"accept_button": "OK",
"open_terms_button": "Open info"
},
"terms": {
"html": "a website in html"
}
}
MyPojo
public class AnnComResponses{
@SerializedName("competition_info")
public CompetitionInfo competitionInfo;
@SerializedName("terms")
public Terms terms;
public class Terms{
@SerializedName("html")
public String html;
public String getTerms() {
return html;
}
}
public class CompetitionInfo{
@SerializedName("headline")
public String headline;
@SerializedName("description")
public String description;
@SerializedName("accept_button")
public String acceptButton;
@SerializedName("open_terms_button")
public String openTermsButton;
public String getHeadline() {
return headline;
}
public String getDescription() {
return description;
}
public String getAcceptButton() {
return acceptButton;
}
public String getOpenTermsButton() {
return openTermsButton;
}
}
}
Upvotes: 2
Views: 406
Reputation: 7792
First, you have several classes inside your main class. Separate them into separate files and do not keep them in the same class. Second in your main class you need to add setters and getters for your properties competitionInfo and terms. Also as a good style make the properties private and your getters and setters keep public.
Upvotes: 0
Reputation: 85
Try using GSON converter with retrofit as below :
RestAdapter restAdapter = new RestAdapter.Builder()
.setLogLevel(RestAdapter.LogLevel.FULL)
.setConverter(new GsonConverter(new GsonBuilder()).create()))
.setEndpoint("your api end point goes here")
.build();
YourAPI api = restAdapter.create(YourAPI.class);
Upvotes: 1