Using Ktor I'm fetching a List like this, which in some cases returns null.
override suspend fun getDevices(accessToken: String): List<Device>? {
return client.get {
url(path = "/devices")
header("Authorization", "Bearer $accessToken")
}
}
However, when the backend returns null I get an Exception:
W/System.err: java.lang.NullPointerException
W/System.err: at io.ktor.client.features.json.serializer.KotlinxSerializer.read(KotlinxSerializer.kt:37)
What is the best approach here? I think the easiest would be to adjust the backend to return [] instead of null, but can it be solved on the client side? Or is there a general agreement that the backend should return [] instead of null?