SerializerRegistry

Thread-safe registry that maps Kotlin types to their TypeSerializer instances.

The registry uses a ConcurrentHashMap internally, so it is safe to read and write from multiple threads without external synchronization.

Example -- registering and retrieving serializers:

val registry = SerializerRegistry()

// Register built-in serializers
BuiltinSerializers.registerAll(registry)

// Register a custom serializer
registry.register(Instant::class, InstantSerializer)

// Retrieve a serializer
val intSerializer = registry.get(Int::class) // TypeSerializer<Int>?
val exists = registry.has(String::class) // true

Since

1.0

See also

Constructors

Link copied to clipboard
constructor()

Functions

Link copied to clipboard
fun <T : Any> get(klass: KClass<T>): TypeSerializer<T>?

Returns the TypeSerializer registered for the given klass, or null if none has been registered.

Link copied to clipboard
fun has(klass: KClass<*>): Boolean

Checks whether a serializer is registered for the given klass.

Link copied to clipboard
fun <T : Any> register(klass: KClass<T>, serializer: TypeSerializer<T>)

Registers a serializer for the given Kotlin klass.