rjaros / kvision

Object oriented web framework for Kotlin/JS
https://kvision.io
MIT License
1.2k stars 67 forks source link

`_children` objects in Tabulator are not being serialized correctly, leading to CCEs #460

Closed MikiLoz92 closed 1 year ago

MikiLoz92 commented 1 year ago

Hi Robert,

I think I have found an issue in regards to the serialization of _children properties in Tabulator.

I see in the toPlainObjTabulator() method, this is being done (ref. A):

if (obj._children != null) {
    obj._children = obj._children.unsafeCast<Array<T>>().map { toPlainObjTabulator(it) }.toTypedArray()
}

And this piece of code, at least for me, is rendering a ClassCastException in the browser:

ClassCastException
    at THROW_CCE (webpack://admin-dashboard-fomantic/./kotlin/kotlin-kotlin-stdlib-js-ir.js?:23530:11)
    at $serializer_3.serialize_32qylj_k$ (webpack://admin-dashboard-fomantic/./kotlin/admin-dashboard-fomantic-frontend.js?:28347:89)
    at StreamingJsonEncoder.encodeSerializableValue_g55msp_k$ (webpack://admin-dashboard-fomantic/./kotlin/kotlinx-serialization-kotlinx-serialization-json-js-ir.js?:3302:20)
    at encodeByWriter (webpack://admin-dashboard-fomantic/./kotlin/kotlinx-serialization-kotlinx-serialization-json-js-ir.js?:2026:13)
    at Json.encodeToString_bhi5ce_k$ (webpack://admin-dashboard-fomantic/./kotlin/kotlinx-serialization-kotlinx-serialization-json-js-ir.js?:293:7)
    at Tabulator.toPlainObjTabulator_9efbw1_k$ (webpack://admin-dashboard-fomantic/./kotlin/kvision-kvision-tabulator.js?:7760:71)
    at Tabulator.toPlainObjTabulator_9efbw1_k$ (webpack://admin-dashboard-fomantic/./kotlin/kvision-kvision-tabulator.js?:7784:26)
    at Tabulator.replaceData_1izf9k_k$ (webpack://admin-dashboard-fomantic/./kotlin/kvision-kvision-tabulator.js?:6925:24)
    at eval (webpack://admin-dashboard-fomantic/./kotlin/kvision-kvision-tabulator.js?:6108:14)
    at ObservableListWrapper.addAll_oxxjwh_k$ (webpack://admin-dashboard-fomantic/./kotlin/kvision-kvision-state.js?:322:9)

As you can see the recursive call to toPlainObjTabulator_9efbw1_k is because it's serializing _children properties. As a means of testing, I tried calling the toPlainObjTabulator method manually on all my rows, and it threw CCE for every properties that had children. I tried calling a modified version of the same method, without the ref.A snippet, and it worked fine.

My question is: is this piece of code still really needed? Now that the tabulator KVision module is using kotlinx.serialization for the serialization of data, shouldn't the _children properties be serialized automatically, without the need of that code? I might be wrong, of course, if so please let me know.

rjaros commented 1 year ago

I think you are right. That should not be necessary and probably just breaks things.

rjaros commented 1 year ago

Fixed in 6.1.0