Kotlin / kotlinx.serialization

Kotlin multiplatform / multi-format serialization
Apache License 2.0
5.42k stars 620 forks source link

Treat JS dynamic as a separate format from JSON #1746

Open ankushg opened 3 years ago

ankushg commented 3 years ago

We use JS dynamic serialization in our webapp, but don't use JS String support.

If dynamic support isn't tied too closely with JSON support, it might be possible to have a much more lightweight dependency just for dynamics in JS, for apps that don't need to worry about string parsing, tokenizing, etc for JSON.

sandwwraith commented 3 years ago

It uses several JsonConfiguration flags and also supports JsonTransformingSerializer (due to the fact that internal implementation is JsonDecoder), but it indeed does not need a parser and tokenizer. We added decodeFromDynamic to Json class because it was a logical place since dynamic and json formats have a lot in common. Not sure if we need a separate module for the dynamic only, though. In theory, DCE in Kotlin/JS should handle this scenario well and remove unnecessary parts of json implementation.