List doesn't have Companion object. What is origin...
# javascript
g
List doesn't have Companion object. What is original Kotlin code?
t
Copy code
fun getItems() = Promise({ resolve : (Items) -> Unit, _  ->
    resolve(Items(JSON.parse(cdItems)))
})
If I try to parse to an array it fails too it can't find the Companion object. I feel like I'm missing whatever part gives me the companion?
Copy code
val nums : Array<Int> = JSON.parse("[1,2,3,4]")
this is also enough to cause this missing companion object error
a
cc @sandwwraith
s
Yes, since
list
is generic and doesn’t have companion object, serializer for it must be specified explicitly (https://github.com/Kotlin/kotlinx.serialization/blob/master/docs/runtime_usage.md#obtaining-serializers)
In your case:
Copy code
val nums: List<Int> = JSON.parse(ArrayListSerializer(IntSerializer), "[1,2,3,4]")