Responses model from Server:
[
{
"at1": true,
"at2": "2021-07-09T08:05:54.307Z",
"at3": "ANDROID",
}
]
Actual response: []
Error : com.squareup.moshi.JsonDataException: Expected BEGIN_ARRAY but was BEGIN_OBJECT at path $
interface SomeInterface {
fun getData(): Single<List<CustomObj>>
}
@Parcelize
data class CustomObj(
val at1: Boolean,
val at2: Date,
val at3: String
) : Parcelable
I tried using @JsonClass(generateAdapter = true)
, but did not help.
Mapping:
fun toEntities(items: List<ServerResponse>?): List<CustomObj> {
return items?.mapNotNull { toEntity(it) } ?: listOf()
}
private fun toEntity(item: ServerResponse): CustomObj? {
return CustomObj(
at1 = item.smth1 ?: return null,
at2 = item.smth2 ?: return null,
at3 = item.smth3 ?: return null
)
}
>(){}.getType());` If this works, then it's issue with the way of how you convert the response to java model.