Custom Adapter to filter objects based on a parameter from an JSON response in Retrofit using Moshi

37 views Asked by At

I am getting an API response as below. The data field is an array of Design objects. I want to filter the contents based on type field into different lists.

{
  "code": 200,
  "data": [
    {
      "id": "1",
      "type": "typeA",
    },
    {
      "id": "1",
      "type": "typeB",
    },
  ]
}

So basically I should be able to get a HashMap<DesignType, List<Design>(). The types are known before-hand.

This is my data class

@JsonClass(generateAdapter = true)
data class Design(
    val id: String,
    val type: DesignType
)

I have gone through some posts but haven't been able to find exactly what I need. This post shows how to extract the list, but I need to filter the contents into different lists.

0

There are 0 answers