All Downloads are FREE. Search and download functionalities are using the official Maven repository.

serialization.SerializationFormat.kt Maven / Gradle / Ivy

The newest version!
package com.hexagonkt.serialization

import java.io.ByteArrayOutputStream
import java.io.InputStream
import java.io.OutputStream
import kotlin.reflect.KClass

interface SerializationFormat {
    val contentType: String
    val extensions: Set
    val isBinary: Boolean

    fun serialize(obj: Any, output: OutputStream)

    fun  parse(input: InputStream, type: KClass): T
    fun  parseObjects(input: InputStream, type: KClass): List

    fun serialize(obj: Any): String =
        if (isBinary) error("$contentType is a binary format")
        else ByteArrayOutputStream().let {
            serialize(obj, it)
            it.toString()
        }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy