Skip to content

How to deserialize escaped json while using Jackson with Retrofit #520

@Elelan

Description

@Elelan
{
    "Data": "[{\"LeaveId\":\"9806595202103221\",\"EmpNo\":\"9806595\",\"LeaveType\":\"ANNUAL\",\"DayType\":\"First Half\",\"LeaveDateFrom\":\"03/22/2021\",\"LeaveDateTo\":\"03/22/2021\",\"Remark\":\"test leave\",\"Substitute\":\"132296\",\"ApplyDate\":\"3/18/2021 2:29:07 PM\",\"AllocatedShiftInTime\":\"\",\"AllocatedShiftOutTime\":\"\",\"ShiftAllocationId\":\"\"},{\"LeaveId\":\"9806595202103191\",\"EmpNo\":\"9806595\",\"LeaveType\":\"CASUAL\",\"DayType\":\"First Half\",\"LeaveDateFrom\":\"03/19/2021\",\"LeaveDateTo\":\"03/19/2021\",\"Remark\":\"firebase message test\",\"Substitute\":\"132296\",\"ApplyDate\":\"3/18/2021 9:28:38 AM\",\"AllocatedShiftInTime\":\"\",\"AllocatedShiftOutTime\":\"\",\"ShiftAllocationId\":\"\"}]",
    "ID": "200"
}
val data = mapper.readTree(responseString).get("Data").asText()

val leaveList: Array<LeaveDto> =
                        mapper.convertValue(mapper.readTree(data), Array<LeaveDto>::class.java)

when using retrofit, how can I de-serialize the above JSON response directly to Kotlin data class without manually mapping using ObjectMapper?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions