Hi everyone, I'm using retrofit and I have the fol...
# squarelibraries
r
Hi everyone, I'm using retrofit and I have the following question: Will retrofit able to parse one field of the response as generic? More details in the 🧵
Api response
Copy code
[
    {
        "type": "p",
        "data": {
            "data1": {

            }
        },
        "version": 3
    },
    {
        "type": "q",
        "data": {
            "data2": {

            }
        },
        "version": 4
    },
    {
        "type": "r",
        "data": {
            "data3": {

            }
        },
        "version": 5
    },
]
Response class
Copy code
class ApiResponse : ArrayList<ApiItem>()

data class ApiItem(
    @SerializedName("data")
    val myData: Data,
    @SerializedName("type")
    val type: String,
    @SerializedName("version")
    val version: Int
)


// how do i do 
data class Data(
    
)
Can i make this
Data
generic? or will have have to explicitly mention each type?
Copy code
data class Data(
    @SerializedName("data1)
    val data1: Data1?,
@SerializedName("data2)
    val data2: Data2?,
@SerializedName("data3)
    val data3: Data3?
)

data class Data1()
data class Data2()
data class Data3()
a
This would depend on the serialiser you are using and not retrofit itself right?
r
ok.. I'm using
Gson
basically if I create a custom deserializer then it should work?