MarkRS
11/24/2022, 11:00 AMAleksei Tirman [JB]
11/24/2022, 2:53 PMMarkRS
11/24/2022, 3:02 PMsuspend fun getJsonFromApi(lang: String, purchases: ArrayList<PurchaseData>): TestListResponseSchema {
return <http://ServerLink.client.post|ServerLink.client.post>("tests") { <etc> }
And that structure is
@ExperimentalMultiplatform
@Serializable
class TestListResponseSchema internal constructor() {
val success: Boolean = false
val message: String? = null
val messages: String? = null
val data: List<TestInventoryInfo> = listOf()
}
And the relevant property there is the "data", the relevant structure is
@Serializable
@Parcelize
@ExperimentalMultiplatform
class TestInventoryInfo( var subdata: TestSubInfo? = null,
@SerialName("width")
var aWidth: Int = 0,
<various other Ints & Strings>): Parcelable { ... }
The failure is this TestSubInfo. Its definition is
@ExperimentalMultiplatform
@Parcelize
@Serializable
data class TestSubInfo(var id: Int = -1,
var sku: String = "",
var renewtime: Long = 0,
var purchasestatus: Int = 0,
var start: Long = 0L,
var end: Long? = null): Parcelable { ... }
As I said, an arrayList of TestSubInfo also arrives in another API call, it works just fine.MarkRS
11/25/2022, 9:31 AMAleksei Tirman [JB]
11/25/2022, 9:50 AMMarkRS
11/25/2022, 9:53 AMMarkRS
11/25/2022, 9:55 AM{
"id": 23,
"fileupdated": "2022-05-21 10:49:53",
"name": "Preliminary 6 (2020)",
"authority": "Association of Irish Riding Clubs (AIRC)",
"thefile": "preliminary-6-2020_en-GB.xml",
"language": "en-GB",
"arena": "20x40",
"width": 20,
"length": 40,
"subdata": {
"id": 23,
"sku": "mm_one_test",
"renewtime": 1669369742,
"purchasestatus": 4,
"start": 1669369339,
"end": null
},
"ordering": 1,
"lorder": 1
}
MarkRS
11/25/2022, 9:57 AMAleksei Tirman [JB]
11/25/2022, 9:58 AMsubdata
, but in the definition of TestListResponseSchema
it’s data
. Is it intended?MarkRS
11/25/2022, 9:59 AMMarkRS
11/25/2022, 10:00 AMAleksei Tirman [JB]
11/25/2022, 10:05 AMfun main(): Unit = runBlocking {
val client = HttpClient(CIO) {
install(ContentNegotiation) {
json(Json {
ignoreUnknownKeys = true
})
}
}
val info = client.get("<http://localhost:3333/>").body<TestInventoryInfo>()
println(info.subdata?.id) // prints 23
}
@Serializable
class TestInventoryInfo(
var subdata: TestSubInfo? = null,
@SerialName("width")
var aWidth: Int = 0,
)
@Serializable
data class TestSubInfo(
var id: Int = -1,
var sku: String = "",
var renewtime: Long = 0,
var purchasestatus: Int = 0,
var start: Long = 0L,
var end: Long? = null
)
Aleksei Tirman [JB]
11/25/2022, 10:05 AMAleksei Tirman [JB]
11/25/2022, 10:06 AMMarkRS
11/25/2022, 10:07 AMAleksei Tirman [JB]
11/25/2022, 10:08 AMAleksei Tirman [JB]
11/25/2022, 10:10 AMMarkRS
11/25/2022, 10:12 AMMarkRS
11/25/2022, 10:12 AMAleksei Tirman [JB]
11/25/2022, 10:13 AMMarkRS
11/25/2022, 10:13 AMAleksei Tirman [JB]
11/25/2022, 10:16 AMisLenient
is false
by default. In Ktor 2.* it’s true
.MarkRS
11/25/2022, 10:17 AMMarkRS
11/25/2022, 12:07 PMMarkRS
11/27/2022, 1:06 PM