<@U5UU34LPK> Yes. It is possible write a “JS” form...
# serialization
e
@karelpeeters Yes. It is possible write a “JS” format implementation that does exactly what you describe. We are considering to include in some future update.
k
Amazing, thanks!
e
Please, create an issue here https://github.com/kotlin/kotlinx.serialization/issues I would also appreciate if you elaborate on your use-cases for this format
k
I'll create an issue, I'm not sure about the use cases though, we really just have some JS data structures that would take some effort to migrate to Kotlin.
b
what is wrong with external interface?
If you don’t want to verify your data it’s exactly that you need
If you can guarantee that some field will be exist just declare it as nullable in Kotlin side.
e
As far as I understand there are two key features people need: verify that data conforms to the expected format (all non nullable fields are present, default values are there if data is absent, etc), support data classes (so that they can be destructured, other custom Kotlin functions invoked, etc)
k
A problem with this approach is that
equals
,
hashcode
and
toString
can't be implemented using extension functions.
I'll be using this util function until there's a proper solution:
Copy code
import kotlinx.serialization.json.JSON as JSONKt
import kotlin.js.JSON as JSONJs

inline fun <reified T: Any> jsToKotlinObject(jsObject: Any) 
        = JSONKt.plain.parse<T>(JSONJs.stringify(jsObject))
Still feels terrible 🙂.