jvmTest.kotlinx.serialization.test.JsonHelpers.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of kotlinx-serialization-json
Show all versions of kotlinx-serialization-json
Kotlin multiplatform serialization runtime library
package kotlinx.serialization.test
import kotlinx.serialization.DeserializationStrategy
import kotlinx.serialization.SerializationStrategy
import kotlinx.serialization.json.*
import java.io.ByteArrayOutputStream
actual fun Json.encodeViaStream(
serializer: SerializationStrategy,
value: T
): String {
val output = ByteArrayOutputStream()
encodeToStream(serializer, value, output)
return output.toString()
}
actual fun Json.decodeViaStream(
serializer: DeserializationStrategy,
input: String
): T = decodeFromStream(serializer, input.byteInputStream())