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

net.dankito.utils.serialization.ISerializer.kt Maven / Gradle / Ivy

The newest version!
package net.dankito.utils.serialization

import java.io.File


interface ISerializer {

    companion object {
        const val SerializationFormatJson = "JSON"
        const val SerializationFormatXml = "XML"
    }


    val serializationFormat: String


    fun serializeObject(obj: Any, outputFile: File)

    fun serializeObject(obj: Any) : String


    fun  deserializeObject(serializedObjectFile: File, objectClass: Class, vararg genericParameterTypes: Class<*>): T?

    fun  deserializeList(serializedObjectFile: File, genericListParameterType: Class) : List?
    fun  deserializeListOr(serializedObjectFile: File, genericListParameterType: Class,
                              defaultValue: List = listOf()) : List

    fun  deserializeSet(serializedObjectFile: File, genericSetParameterType: Class) : Set?
    fun  deserializeSetOr(serializedObjectFile: File, genericSetParameterType: Class,
                             defaultValue: Set = setOf()) : Set

    fun  deserializeMap(serializedObjectFile: File, keyParameterType: Class,
                                    valueParameterType: Class) : Map?
    fun  deserializeMapOr(serializedObjectFile: File, keyParameterType: Class,
                          valueParameterType: Class, defaultValue: Map = mapOf()) : Map


    fun  deserializeObject(serializedObject: String, objectClass: Class, vararg genericParameterTypes: Class<*>) : T

    fun  deserializeList(serializedObject: String, genericListParameterType: Class) : List?
    fun  deserializeListOr(serializedObject: String, genericListParameterType: Class,
                              defaultValue: List = listOf()) : List?

    fun  deserializeSet(serializedObject: String, genericSetParameterType: Class) : Set?
    fun  deserializeSetOr(serializedObject: String, genericSetParameterType: Class,
                             defaultValue: Set = setOf()) : Set?

    fun  deserializeMap(serializedObject: String, keyParameterType: Class,
                                    valueParameterType: Class) : Map?
    fun  deserializeMapOr(serializedObject: String, keyParameterType: Class,
                            valueParameterType: Class, defaultValue: Map = mapOf()) : Map


    fun isSerializingToJson(): Boolean {
        return serializationFormat.equals(SerializationFormatJson, true)
    }

    fun isSerializingToXml(): Boolean {
        return serializationFormat.equals(SerializationFormatXml, true)
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy