Tambosa
Tambosa

Reputation: 1

How to defer/delay parsing using kotlinx.serialization?

I am currently looking for a way to partially parse json and postpone parsing of certain structures. In other words, I want to indicate that field should be kept as rawJson / string even though it is an object. This way I could save time on initial parsing, and continue parsing of raw value at a later time.

I already achieved saving object as raw value by writing custom KSerializer. However this does not save time on initial parsing since kotlinx.serialization already parsed entire json into a tree of JsonElements. There is an open issue on GitHub describing the problem in detail https://github.com/Kotlin/kotlinx.serialization/issues/1058

I am wondering if there are alternative ways to alter default library behavior, for example is there a way to change initial decoding process by supplying library custom Decoder to replace JsonTreeDecoder?(https://kotlinlang.org/api/kotlinx.serialization/kotlinx-serialization-core/kotlinx.serialization.encoding/-decoder/)

Or maybe it is possible to skip parsing using @Transient annotation, but I still need to save what was skipped somewhere.

Upvotes: 0

Views: 32

Answers (0)

Related Questions