StringProperties

Transforms a Serializable class' properties into a single flat String representing the class data in the properties format.

If the given class has non-primitive property d of arbitrary type D, D values are inserted into the same map; keys for such values are prefixed with string d.:

@Serializable
class Data(val property1: String)

@Serializable
class DataHolder(val data: Data, val property2: String)

val string = StringProperties.encodeToString(properties)
// string contents will be the following:
"""
property2 = value2
data.property1 = value1
"""

If the given class has a List property l, each value from the list would be prefixed with l.N., where N is an index for a particular value. Map is treated as a [key,value,...] list.

Conversely, this class can convert a properties string into a Serializable class instance.

@Serializable
class Data(val property1: String)

@Serializable
class DataHolder(val data: Data, val property2: String)

val string = """
property2 = value2
data.property1 = value1
"""
val data = StringProperties.decodeToString(string, DataHolder.serializer())
// data contents will be the following:
// DataHolder(data = Data(property1 = "value1"), property2 = "value2")

Parameters

conf

A PropertiesConf which contain configuration for customising the output string.

Inheritors

Types

Link copied to clipboard

A Properties instance that can be used as default and does not have any SerializersModule installed.

Properties

Link copied to clipboard

Functions

Link copied to clipboard
open override fun <T> decodeFromString(deserializer: DeserializationStrategy<T>, string: String): T

Decodes properties from the given string to a value of type T using the given deserializer. String values are converted to respective primitive types using default conversion methods. T may contain properties of nullable types; they will be filled by non-null values from the map, if present.

Link copied to clipboard

Decodes properties from given propertiesString, assigns them to an object using serializer for reified type T and returns this object. String values are converted to respective primitive types using default conversion methods. T may contain properties of nullable types; they will be filled by non-null values from the map, if present.

Link copied to clipboard

Decodes properties from the given string to a Map.

Link copied to clipboard

Encodes properties from the given map to a properties String. null values are omitted from the output.

Link copied to clipboard
open override fun <T> encodeToString(serializer: SerializationStrategy<T>, value: T): String

Encodes properties from the given value to a properties String using the given serializer. null values are omitted from the output.

Link copied to clipboard

Encodes properties from given value to a string using serializer for reified type T and returns this string. Converts all primitive types to String using toString method. null values are omitted from the output.