0

How can I post following parameter in retrofit through post method as an input parameter of a request?

widget:[
    {
        "id": 37,
        "fkAnagraficaId": 100,
        "name": "Fatture",
        "position": 1
    },
    {
        "id": 38,
        "fkAnagraficaId": 100,
        "name": "Ordini",
        "position": 2
    }
]
letsintegreat
  • 3,328
  • 4
  • 18
  • 39
giordy16
  • 275
  • 1
  • 12
  • Basically what you're looking for is called `@Body` annotation on your retrofit POST method call as annotation to method parameter. – Jeel Vankhede Jan 29 '21 at 15:47

2 Answers2

1

You can very well send array directly as param like this

@Headers({
    "Content-type: application/json"
})
Response postWidgets(@Body List<String> widgets);

But if you want to send as JSON you mentioned ( with widgets as key and array as value) then you may need to write POJO having widgets as array field and use that POJO instance here

@Headers({
    "Content-type: application/json"
})
Response postWidgets(@Body MyPojo myPojo);
Pavan
  • 819
  • 6
  • 18
0

Retrofit uses JSON so you can use ["something0", "somethingElse"] you can also look at: How to post array in retrofit android