Deepak Nulu
10/21/2022, 4:46 AMjavax.json.stream.JsonParser
where I get to handle the lexer tokens the way I want.
I am developing a multi-platform library that is currently JVM-only since it uses java.io.Reader
and java.io.Writer
. It also uses javax.json.stream.JsonParser
to parse JSON as it streams in. I currently cannot use kotlinx.serialization
for decoding since I have a specific representation in JSON that is not suitable for kotlinx.serialization
.
I currently use my library in a Ktor-based server to convert JSON in POST requests as they stream in. I also need to use my library on the client side to convert JSON in responses as they stream in. So I want to make my library a multi-platform library so that I can use it on the server side (Kotlin/JVM) as well as the client side (Kotlin/JS).
I went looking for java.io.Reader
replacements that are multi-platform. I narrowed it down to Okio and Ktor’s ByteReadChannel
. I would prefer to use Ktor since it is from JetBrains, and also because I can use it on both the client and the server (Okio is only client side).
The next thing I went looking for is a multi-platform streaming JSON decoder. I found some classes in kotlinx.serialization
and I see that it is supported for Okio. I could be wrong, but I did not find it supported for Ktor’s ByteReadChannel
.Aleksei Tirman [JB]
10/21/2022, 7:26 AMjava.io.Reader
and classes from Okio provide blocking I/O but Ktor uses non-blocking one. We have the general-purpose asynchronous multiplatform I/O library in development but there is no ETA yet. You are right about integration between kotlinx.serialization
and Okio libraries https://github.com/Kotlin/kotlinx.serialization/releases/tag/v1.4.0-RC.jw
10/21/2022, 11:19 AMDeepak Nulu
10/21/2022, 5:03 PMjw
10/21/2022, 5:03 PMDeepak Nulu
10/21/2022, 5:06 PMDeepak Nulu
10/21/2022, 5:08 PMDeepak Nulu
10/21/2022, 5:16 PM