TypeSerializer

interface TypeSerializer<T>

Core interface for converting configuration values between their typed representation and a raw storage form.

Implement this interface to support custom types in KConfig. Every implementation must be able to round-trip: calling deserialize on the output of serialize must produce an equivalent value.

Example -- a custom serializer for java.time.Instant:

object InstantSerializer : TypeSerializer<Instant> {
override fun serialize(value: Instant): Any = value.toString()
override fun deserialize(raw: Any): Instant = Instant.parse(raw.toString())
}

// Register it:
registry.register(Instant::class, InstantSerializer)

Since

1.0

Parameters

T

The typed value this serializer handles.

See also

Inheritors

Functions

Link copied to clipboard
abstract fun deserialize(raw: Any): T

Converts a raw storage value back into the typed representation.

Link copied to clipboard
abstract fun serialize(value: T): Any

Converts a typed value into a raw form suitable for storage (e.g. a string, number, or map).