Hi, I updated kotlin version form 1.7.20 to 1.8.21 im my project, and while I try to parse json I get an error.
Expected start of the array '[', but had 'EOF' instead at path: $
This code works properly on kotlin 1.7.20 but throws an exception on 1.8.21 (1.8.20 too)
inline fun <reified T> String.listFromJson() = json.decodeFromString<List<T>>(this)
In both cases I use the latest
1.5.1
library.
What different between versions?
Where I can find what changes have been made?
c
Chris Lee
06/29/2023, 1:22 PM
The String being parsed is empty, resulting in that exception (it’s expecting a JSON array). Issue may not be with serialization - it’s doing what’s expected given that input data, you’ll need to track down why that string is empty.
m
Mateusz Kolbusz
06/29/2023, 2:47 PM
Thank you for your response Chris, meanwhile I found working solution
Copy code
inline fun <reified T> String.listFromJson(): List<T>? =
json.decodeFromString(json.parseToJsonElement(this).jsonPrimitive.content)