https://kotlinlang.org logo
#ktor
Title
# ktor
n

napperley

05/02/2019, 1:38 AM
Puzzled with the JSON deserialization error from the Ktor Client library (using version 1.1.4 with Gson 2.8.5) on Android: Fail to run receive pipeline: io.ktor.client.call.NoTransformationFoundException: No transformation found: class io.ktor.client.engine.android.AndroidHttpResponse -> class kotlin.Array Why does the error mention AndroidHttpResponse?
Trying to get a Array of BatteryInfo. Below is the BatteryInfo model:
Copy code
data class BatteryInfo(
    @Expose
    val id: Int,
    @Expose
    val timestamp: Timestamp,
    @Expose
    val channel: Int,
    @Expose
    val battery: Battery,
    @Expose
    val site: Int
)
Here is the Timestamp model:
Copy code
data class Timestamp(
    @Expose
    val year: Int,
    @Expose
    @SerializedName("monthValue")
    val month: Int,
    @Expose
    @SerializedName("dayOfMonth")
    val day: Int,
    @Expose
    val hour: Int,
    @Expose
    val minute: Int
)
Here is the Battery model:
Copy code
@Suppress("ArrayInDataClass")
data class Battery(
    @Expose
    val voltage: Double,
    @Expose
    val current: Double,
    @Expose
    val temp: Double,
    @Expose
    val socTemp: Double,
    @Expose
    val charger: Boolean,
    @Expose
    val heater: Boolean,
    @Expose
    val connect: Boolean,
    @Expose
    val sentMean: Double,
    @Expose
    val cells: Array<BatteryCell>,
    @Expose
    val disconnect: Boolean
)
Here is the BatteryCell model:
Copy code
data class BatteryCell(
    @Expose val id: Int,
    @Expose val meanVolt: Double,
    @Expose val temp: Double,
    @Expose val load: Double = 0.0
)
All other web APIs (HTTP based) that return JSON in the response work fine with the Ktor Client (Android version) library. The custom CLI client which also uses Ktor Client (JVM version) library works fine with ALL web APIs.
g

guyheylens

05/02/2019, 3:57 PM
I also had some weird pipeline errors lately, I configured the ContentNegotiation and was fixed.
21 Views