0

My api now accepts true json objects as arguments, before that, I had to use "url encoding" to get there.

For most of my retrofit requests, the translation goes quite smoothly, but I have this one request that borther me :

@FormUrlEncoded
@POST("/api/**")
Call<QuestionAnswerResponse> postResponse(
    @Path("id") String id, 
    @Field("self[text]") String text, 
    @Field("self[medias]") List<String> medias);

that I want to become :

@POST("/api/**")
Call<QuestionAnswerResponse> postResponse(
    @Path("id") String id, 
    @Body ArgType args);

I should have in ArgType a public Map<String, Object> self ? How to do with this kind of types ?

Thanks,

Renaud Favier
  • 1,645
  • 1
  • 17
  • 33
  • depends on how the server expects the json object to be. Probably simply `{ "text": "...", "medias" : [ "..", "..", ...] }`, no self, just those fields. – zapl May 23 '16 at 15:20
  • nope, He expects self infortunatly (there are more arguments I didn't put, He expects something like ```{key:"value", self:{ "text": "...", "medias" : [ "..", "..", ...] }}``` – Renaud Favier May 23 '16 at 15:23
  • but I don't know how to get gson to translate my class like that (beside a custom converter of course) – Renaud Favier May 23 '16 at 15:23
  • Like those two: http://pastebin.com/XyWP5vPH? But I think you can actually use a `Map` like you did. (edit: link broken) – zapl May 23 '16 at 15:29
  • Of course ! thanks a lot – Renaud Favier May 23 '16 at 15:35

0 Answers0