LastExceed
03/18/2020, 2:16 PMsuspend fun main() {
val items = MarketAPI.getItems()
for (index in items.indices) {
println(items[index])
}
items.forEach {
println(it)
}
}
the return type of MarketAPI.getItems()
is List<Item>
where Item
is a simple data class storing 3 Strings.
the first loop works fine, the second one gives me this error: https://hastebin.com/ewuvakikuy
how is this possible? how can the way i iterate through the items affect the serialization AFTER it happens?
I cant even figure out where exactly it happens. the stacktrace says line 12 in main.kt, however that file only has 11 lines. I set a breakpoint and stepped through, the crash occurs as soon as i reach the second loop. but due to coroutine shenanigans the stacktrace isnt very helpfulJakub Pi
03/18/2020, 2:25 PMLastExceed
03/18/2020, 2:26 PMJakub Pi
03/18/2020, 2:27 PMLastExceed
03/18/2020, 2:27 PMJakub Pi
03/18/2020, 2:28 PMLastExceed
03/18/2020, 2:29 PMJakub Pi
03/18/2020, 2:29 PMcypher121
03/18/2020, 2:29 PMcypher121
03/18/2020, 2:30 PMLastExceed
03/18/2020, 2:30 PMcypher121
03/18/2020, 2:31 PMLastExceed
03/18/2020, 2:32 PMJakub Pi
03/18/2020, 2:32 PMJakub Pi
03/18/2020, 2:33 PMLastExceed
03/18/2020, 2:33 PMcypher121
03/18/2020, 2:34 PMItem it = (Item) items.next()
cypher121
03/18/2020, 2:35 PMLastExceed
03/18/2020, 2:36 PMcypher121
03/18/2020, 2:38 PMJakub Pi
03/18/2020, 2:39 PMLastExceed
03/18/2020, 2:39 PMLastExceed
03/18/2020, 2:39 PMLastExceed
03/18/2020, 2:40 PMJakub Pi
03/18/2020, 2:40 PM<Map<String, Map<String, ActualDataType>>>
Problem is probably thereLastExceed
03/18/2020, 2:40 PMJakub Pi
03/18/2020, 2:41 PMLastExceed
03/18/2020, 2:42 PMLastExceed
03/18/2020, 2:42 PMJakub Pi
03/18/2020, 2:52 PMJakub Pi
03/18/2020, 2:52 PMLastExceed
03/18/2020, 2:55 PMJakub Pi
03/18/2020, 2:57 PMJakub Pi
03/18/2020, 2:58 PMLastExceed
03/18/2020, 3:00 PMTry replacing it with List<Item> explicitlytried, didnt help
Nico Buescher
03/18/2020, 3:01 PMLastExceed
03/18/2020, 3:01 PMNico Buescher
03/18/2020, 3:02 PMLastExceed
03/18/2020, 3:02 PMLastExceed
03/18/2020, 3:02 PMJakub Pi
03/18/2020, 3:11 PMcypher121
03/18/2020, 3:31 PMLastExceed
03/18/2020, 3:32 PMsuspend fun getItems() =
httpClient.get<Map<String, Map<String, List<Item>>>>(root + "items").entries.first().value.entries.first().value
this works Edit: now it doesnt anymore. what is this sorcery
private suspend inline fun <reified ActualDataType> HttpClient.getUnwrapped(url: String) = get<Map<String, Map<String, ActualDataType>>>(url).entries.first().value.entries.first().value
suspend fun getItems() = httpClient.getUnwrapped<List<Item>>(root + "items")
this doesn't. why?LastExceed
03/18/2020, 3:33 PMit would be better in this case to remove the type argument entirely, since this doesn't look particularly reusable either waywhat do you mean? by using a type argument i can use this function for literally every api call
cypher121
03/18/2020, 3:35 PMLastExceed
03/18/2020, 3:35 PMLastExceed
03/18/2020, 3:35 PMcypher121
03/18/2020, 3:35 PMJakub Pi
03/18/2020, 5:36 PMLastExceed
03/18/2020, 5:38 PMList<Item>
where Item
is a data class containing 3 string variablesLastExceed
03/18/2020, 5:38 PMJakub Pi
03/18/2020, 5:38 PMLastExceed
03/18/2020, 5:39 PMJakub Pi
03/18/2020, 5:39 PMJakub Pi
03/18/2020, 5:40 PM