what's the best way to have a kotlin class compile...
# javascript
g
what's the best way to have a kotlin class compile down to a plain JSON object to send to a REST endpoint?
c
I’ve been using the native Serialization library and have really liked it so far https://github.com/Kotlin/kotlinx.serialization
g
Thanks I'll give that a try
@Casey Brooks There's not much documentation for JS on it, do I use it the same way that its used for JVM?
c
I actually haven’t personally done it with JS, but yeah it looks to work the exact same. Most of the work is done by the compiler
b
сс @sandwwraith
s
Serializing to JSON works via same API as on JVM; serializing to
dynamic
js type is on the roadmap
b
Also it may be interesting for you https://youtrack.jetbrains.com/issue/KT-21653
g
@sandwwraith If I have a JSON object coming from the server, am I able to serialize that into a Kotlin class on the JS client side using the Serialization library or will I need to do it by hand?
c
Yeah, you should be able to use the Serialization lib for that, regardless of whether the server produced it using the Serialization lib or not. As long as you have a model to match the JSON response, it should deserialize just fine on both the JVM and JS