2

I have a JSON like below.

{
    "code": "success",
    "response": {
        "data": {
            "xyz": "abc.pdf",
            "abc: "efgh.pdf"
        }
    },
    "message": "Files downloaded Successfully"
}

Inside data in the response object, the key is dynamic (xyz, abc etc). I am using Moshi in the retrofit converter. My data classes are as follows.

data class RestResponse<T> (
    val code: String,
    val message: String,
    val response: T
)

data class ProposalDownloadResponse(val data: DownloadData)

data class DownloadData(val list: Map<String, String>)

But I am getting null in the list after parsing. Though I have data.

Refrofit function is like below.

@POST
suspend fun downloadProposal(
    @Url url: String,
    @Header("accessToken") key: String,
    @Body flightDetails: FlightDetails,
): GenericResponse<RestResponse<ProposalDownloadResponse>>
Shihab Uddin
  • 6,699
  • 2
  • 59
  • 74

1 Answers1

2

The reason is You are nesting Object which is not needed . Your data itself is of Type Map<String, String> so DownloadData is not required. Use it as Below.

data class ProposalDownloadResponse(val data: Map<String, String>)
ADM
  • 20,406
  • 11
  • 52
  • 83