1
{
    "result": "success",
    "response_code": 200,
    "message": "data list",
    "data": [
        {
            "Assigned": "14",
            "Closed": "150",
            "Escalated TTO": "102",
            "Escalated TTR": "2",
            "New": "44",
            "Pending": "4",
            "Resolved": "14"
        }
    ]
}

Above is the response that I want to parse, but I don't want to create a static POJO for it. The model should be dynamic so that even if there is another key-value pair in the above response, like as shown below, the response is able to be parsed I guess it is possible using HashMap.

{
    "result": "success",
    "response_code": 200,
    "message": "data list",
    "data": [
        {
            "Assigned": "14",
            "Closed": "150",
            "Escalated TTO": "102",
            "Escalated TTR": "2",
            "New": "44",
            "Pending": "4",
            "Resolved": "14",
            "xx": "xx",
            "xx": "xx",
            "xx": "xx",


        }
    ]
}
Shikhar
  • 644
  • 1
  • 10
  • 20

1 Answers1

2

As discussed in the comments, the ideal scenario would be a Map<String, String>. The models could look like (assuming you're using Gson. Should be similar for others):

data class ApiResponse(
  @SerializedName("result")
  val result: String,
  @SerializedName("responseCode")
  val responseCode: Int,
  @SerializedName("message")
  val message: String,
  @SerializedName("data")
  val data: List<Map<String, String>>
)
Fred
  • 16,367
  • 6
  • 50
  • 65