Edoardo Luppi
05/25/2025, 3:12 PMdynamic
. I'm trying to implement a comparable solution with KSP, that is, for each annotated class generating an external declaration + to/from converter functions. This seemed like the most optimal solution in terms of time and effort.
Maybe this kind of stuff could be part of the plain object plugin?Artem Kobzar
05/25/2025, 5:29 PMEdoardo Luppi
05/25/2025, 5:35 PM@JsExport
@JsSerializable // Marker annotation
class Example(val one: Int, val two: String)
We end up with the compiler plugin adding in a companion + the external interface:
@JsExport
@JsSerializable // Marker annotation
class Example(val one: Int, val two: String) {
companion object {
fun toJso(value: Example): ExampleJso { ... }
fun fromJso(jso: ExampleJso): Example { ... }
}
}
// External added by compiler
@JsExport
external interface ExampleJso {
val one: Int
val two: String
}
This is invisible on the Kotlin side, but visible from JS/TS.Artem Kobzar
05/25/2025, 5:38 PMEdoardo Luppi
05/25/2025, 5:40 PMpostMessage
.
The fact an external interface is generated automatically means I don't have to create one myself on the TS side.Edoardo Luppi
05/25/2025, 5:41 PMturansky
05/25/2025, 6:12 PMSerializable
marker interface in Kotlin Wrappers 😉.
For future more strict API (postMessage
for example).turansky
05/25/2025, 6:16 PMturansky
05/25/2025, 6:17 PMEdoardo Luppi
05/25/2025, 6:50 PMturansky
05/25/2025, 8:01 PMturansky
05/25/2025, 8:02 PMkotlinx-serialization
looks like common solution for themEdoardo Luppi
05/25/2025, 8:04 PMdynamic
, and deserialize from dynamic
without any sort of type safety. I still need to manually code dozens of types in TS to represent the plain objects. Add in the size factor, and that's why I'm going down the KSP route.turansky
05/25/2025, 8:06 PMEdoardo Luppi
05/25/2025, 8:08 PMturansky
05/26/2025, 12:28 AMturansky
05/26/2025, 12:29 AMturansky
05/26/2025, 12:37 AMwhole-program
granularityArjan van Wieringen
05/26/2025, 11:24 AMEdoardo Luppi
05/26/2025, 11:29 AMtoJSON
is mainly used to serialize to a string tho, not an object.Arjan van Wieringen
05/26/2025, 11:42 AMEdoardo Luppi
05/26/2025, 11:44 AMArjan van Wieringen
05/26/2025, 11:45 AMEdoardo Luppi
05/27/2025, 5:36 PMexternal interface
that maps to the DTO class, that's probably the most frustrating part to code manually.turansky
05/27/2025, 5:38 PMturansky
05/27/2025, 5:38 PM