Hello, How to implement this below classes in bett...
# codingconventions
k
Hello, How to implement this below classes in better way? Class 1 has - DataResponse, Meta Response and List<IncludedResponse>
Copy code
@Serializable
data class ApiResponse<T>(
    @SerialName("data") val data: DataResponse<T>,
    @SerialName("meta") val meta: MetaResponse?,
    @SerialName("included") val included: List<IncludedResponse>? = null
)
Class 2 has - List<DataResponse>, MetaResponse, List<IncludedResponse>
Copy code
@Serializable
data class ListApiResponse<T>(
    @SerialName("data") val data: List<DataResponse<T>>,
    @SerialName("meta") val meta: MetaResponse?,
    @SerialName("included") val included: List<IncludedResponse>? = null
)
In both the class 
List<IncludedResponse>?
 & 
MetaResponse
  both are common only uncommon thing is 
DataResponse
 & 
List<DataResponse>
 .
d
How about this (leaving out the serialization annotations):
Copy code
data class ApiResponse<T>(val data: T, val meta: MetaResponse?, val included: List<IncludedResponse>?)

typealias PlainApiResponse<T> = ApiResponse<DataResponse<T>>
typealias ListApiResponse<T> = ApiResponse<List<DataResponse<T>>>
1
👍 1
k
Let me try out this
Yeah looks perfect 👍
t
btw, if your variable name matches the @SerialName, you can omit the annotation.
1