My JSON Resoponse looks like-
{
"body": {
"count": 4,
"sender": "margarete20181570"
},
"inserted_at": "2020-05-07T05:48:14.465Z",
"type": 1
},
{
"body": "savanna19562530 hit the SOS button!",
"inserted_at": "2020-05-06T09:17:36.658Z",
"type": 2
}
And I am using the Data Class like below to parse the above JSON, what is wrong here!
data class Notification(val body: String, val inserted_at: String, val type: Int) {
constructor(
msgBody: MessageNotification,
inserted_at: String,
type: Int
) : this(msgBody.sender + "Sent you " + msgBody.count + "Messages", inserted_at, type)
}
But this dosent work it gives parsing error like - Expected String , got object
My Api call looks like-
@GET("notifications")
suspend fun getNotifications(
@HeaderMap headers: HashMap<String, String>
): Response<List<Notification>>
The main objective is how to remodel the code such that the Notification
model class' different constructor will be called on different cases such that it does not give such error expecting string, got object
or expecting object got string
How should I improve my code to parse the response?
Any help is appreciated!