You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Trying to use Wrapped adapter to avoid creating a wrapper object SurveyAnswerPayload like so:
public class SurveyAnswer {
@Json(name = "questionId")
public String questionId;
@Json(name = "answer")
public String answer;
}
public interface SurveyService{
@POST("surveys/{surveyId}/answers")
@Wrapped(path = {"answers"})
Call<Void> postAnswers(@Path("surveyId") String surveyId, @Body List<SurveyAnswer> answers);
}
Sadly this doesn't work. It serializes into [{"questionId":"1","answer":"A"},{"questionId":"2","answer":"B"}]
Wrapper class SurveyAnswerPaylod is needed here to get it wrapped in a parent "{"answers":[{"questionId":"1","answer":"A"},{"questionId":"2","answer":"B"}]}"
class SurveyAnswerPayload{
@Json(name = "answers")
public List<SurveyAnswer> answers;
}
The text was updated successfully, but these errors were encountered:
Wrapped adapter is extremely convenient when deserializing unnecessarily wrapped json responses without having to create wrapper classes.
But it doesn't seem to work when serializing
POST
data.Endpoint:
POST api/{surveyId}/answers
Example Body:
Trying to use Wrapped adapter to avoid creating a wrapper object
SurveyAnswerPayload
like so:Sadly this doesn't work. It serializes into
[{"questionId":"1","answer":"A"},{"questionId":"2","answer":"B"}]
Wrapper class
SurveyAnswerPaylod
is needed here to get it wrapped in a parent "{"answers":[{"questionId":"1","answer":"A"},{"questionId":"2","answer":"B"}]}
"The text was updated successfully, but these errors were encountered: