Meta is null when trying to parse json String to JsonApiModel

14 Views Asked by At

I am following JsonAPI schema and using the kotlin-jsonapix library. When trying to convert from json, I am always getting null meta.

This is my json:

{
  "data": {
    "type": "st",
    "id": "1",
    "attributes": {
      "end_date": "2222-12-31",
      "payment_id": "1",
      "start_date": "2020-12-13",
      "status": "ACTIVE"
    },
    "meta": {
      "detail": "user details"
    }
  }
}

This is my model:

@Serializable
@JsonApiX(type = "st")
data class StModel(
    @SerialName("end_date") val subscriptionEndDate: String? = null,
    @SerialName("start_date") val subscriptionStartDate: String? = null,
    @SerialName("status") val subscriptionStatus: String? = null,
    @SerialName("payment_id") val paymentId: String? = null,
) : JsonApiModel()

@Serializable
@JsonApiXMeta(type = "st")
data class StMeta(val detail: String) : Meta

and I am using below statement to get StModel from jsonString:

TypeAdapter_StModel().convertFromString(jsonString)

and I get null meta.

Can someone please explain if I am doing anything wrong or is it an issue with the library itself.

0

There are 0 best solutions below