I have to send data in the following model:
{
"TransactionType": "testType",
"TransactionReference": "testSectionReference",
"TransactionDate": "2018-10-22T06:22:30.632Z",
"TransactionLines": [
{
"ProductReference": "testProductReference",
"ShipDate": "2018-10-22T06:22:30.632Z",
"Quantity": 1,
"AwardAmount": 2.0,
"TotalAmount": 3.0
}
]
}
I do so by creating a transactionBody
, which I send as a body in the request like this:
@POST("/myCustomUrlPath")
Call<Transaction> createTransaction(
@Body TransactionBody transactionBody
);
The TransactionBody
has the following parameter:
transactionType - String
transactionReference - String
transactionDate - String
transactionLines - TransactionLines //(my custom model)
All seems good, until I test the request and see that the properties of my TransactionLines
model are not sent like this:
"productReference":"testProductReference"
but instead they are sent with my java class path like this:
"model.transactionLines.productReference":"testProductReference"
This of course makes my server return an error, because it's expecting productReference
and not model.transactionLines.productReference
. How do I remove the path of my java class model before the variable name?
Edit:
I don't think my problem is anything close to what is suggested as a possible already asked question. They are asking for posting an array in json and I am having problem with posting the name of a variable in a custom object used in json post.
However, @Jeel Vankhede is right. Serializing the name of the variable removed the path of my java class and now the request is filled with correct data. Thank you!