net.dankito.utils.serialization.ISerializer.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of java-utils Show documentation
Show all versions of java-utils Show documentation
Some basic utils needed in many projects
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)
}
}