json-kotlin-nonblocking
Non-blocking JSON serialization for Kotlin
This library allows a JSON object to be serialized to a non-blocking stream, for example a ByteWriteChannel
. It is designed to be used in conjunction with the co-pipelines library, as follows:
fun serializeToByteChannel(obj: Any?, channel: ByteWriteChannel) {
val pipeline = CoEncoderFactory.getEncoder(Charsets.UTF_8, ByteChannelCoAcceptor(channel))
pipeline.outputJSON(obj)
}
In this example, the getEncoder()
function will create a non-blocking pipeline that takes characters (the stringified JSON), converts them to a UTF-8 byte stream and pipes it to the channel.
This a very much a work in progress; stay tuned for more developments (and with any luck, more documentation).
Dependency Specification
The latest version of the library is 0.6, and it may be obtained from the Maven Central repository.
Maven
<dependency>
<groupId>net.pwall.json</groupId>
<artifactId>json-kotlin-nonblocking</artifactId>
<version>0.6</version>
</dependency>
Gradle
implementation 'net.pwall.json:json-kotlin-nonblocking:0.6'
Gradle (kts)
implementation("net.pwall.json:json-kotlin-nonblocking:0.6")
Peter Wall
2021-04-25