android retrofit ,post whole Pojo using this forma

2019-03-05 05:24发布

问题:

I want to post this kind of request in retrofit2 so if someone have idea about it then it would be great help of mine.

reqObject={"task":"singleUser","taskData":{"userID":"1"}}

回答1:

Yes, good Question It is some what not understandable for Beginner.

So I combining some Answers for you.

first step

make your Json -> model class (or POJO class)

  1. From GsonFormattor plugin

This plug-in convert your Json to Model class

  1. Pojo genrator

Go to this link , copy and paste Your Json and simply make your model class.

OK , we completed our first step

Second Step

Set all value to your Model class what You want from getter() setter().

Retrofit having @Body annotation that use in your case

@POST("/jayson")
FooResponse postJson(@Body MyGsonModelClass body);

Where MyGsonModelClass is class we made from first step.