best way to post object with retrofit request
my request is
{
"store_id": 1,
"coupon_code":"15135",
"payment_method":"visa",
"address_id":0,
"temp_address" :{
"lat" : "45.5555555",
"lng" : "45.5555555",
"address_description": "test info",
"address_title" : "test info",
"address_type" : "test info",
"address_name" : "test info",
}
}
is send request like this
@Multipart
@POST("orders")
fun checkOut(
@Part("store_id") store_id: RequestBody? = null,
@Part("coupon_code") coupon_code: RequestBody? = null,
@Part("address_id") address_id: RequestBody? = null,
@Part("payment_method") payment_method: RequestBody? = null,
@Part("note") note: RequestBody? = null,
): Deferred<Response<DefaultResponse>>
how add temp_address with my request to send this data
Solution 1:
You can just send it all in one object!
@POST("orders")
suspend fun checkOut(@Body dataModel: DataModel): DefaultResponse?
class DataModel(
@SerializedName("store_id")
@Expose
var storeId: Int? = null,
@SerializedName("coupon_code")
@Expose
var couponCode: String? = null,
@SerializedName("payment_method")
@Expose
var paymentMethod: String? = null,
@SerializedName("address_id")
@Expose
var addressId: Int? = null,
@SerializedName("temp_address")
@Expose
var tempAddress: TempAddress? = null
)
class TempAddress(
@SerializedName("lat")
@Expose
var lat: String? = null,
@SerializedName("lng")
@Expose
var lng: String? = null,
@SerializedName("address_description")
@Expose
var addressDescription: String? = null,
@SerializedName("address_title")
@Expose
var addressTitle: String? = null,
@SerializedName("address_type")
@Expose
var addressType: String? = null,
@SerializedName("address_name")
@Expose
var addressName: String? = null
)