how can i post nested json objects to server in retrofit [duplicate]


how can i post nested json objects to server in retrofit [duplicate]



This question already has an answer here:



How can I post to the server? I need to post an JSON object using Retrofit 2. My JSON object is


{
"test_id":5,
"user_id":null,
"org_id":2,
"schedule_id":15,
"group_id":null,
"next_section_id":"",
"current_section":
{}
}



This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.




2 Answers
2



make give json into one pojo class and pass into api calling like..


@POST("path")
Call<ResponseData> passJsonData(@Body JsonData jsonData); // here pass your request data pojo class object..



when calling that time only create object and pass all data into object and pass into api call method.



like ..


JsonData data=new JsonData();
data.setId("1");
data.setName("Abcd");
Call<ResponseData> responseCall =apiInterface.passJsonData(data);





i update my answer.
– Android Team
Jun 30 at 6:59





how can i post multiple object
– Paramasivam Mathesh
Jun 30 at 7:39





store all boject into array then pass array
– Android Team
Jun 30 at 8:24





thank i will tried but it not worked stackoverflow.com/questions/51113045/…
– Paramasivam Mathesh
Jun 30 at 9:12



Below are some ways to achieve this:



1.


@POST("/path")
void sendPost(@Body EventPayload body, Callback<Response> onSuccess);



here EventPayload is the POJO representation of your request



2.


@POST("/path")
void sendPost(@Body String body, Callback<Response> onSuccess);



here body is the serialized JSON in the string form