Package eu.vstoyanov.natsy.codec
Class CodecRegistry.Builder
-
- All Implemented Interfaces:
public final class CodecRegistry.BuilderBuilder for CodecRegistry
-
-
Constructor Summary
Constructors Constructor Description CodecRegistry.Builder()
-
Method Summary
Modifier and Type Method Description final UnitdefaultContentType(String contentType)Set the default content type for auto-selection final <T extends Any> UnitregisterJson(KClass<T> type, KSerializer<T> serializer)Register a JSON codec for a specific type using kotlinx. final <T extends Any> Unitregister(KClass<T> type, MessageCodec<T> codec)Register a custom codec final CodecRegistry.BuilderconfigureJson(Function1<JsonBuilder, Unit> block)Adjust the Json instance that backs every JSON codecThe block starts from the registry's defaults (lenient, unknown keys ignored, defaults not encoded) and changes only what it names:
A codec captures the configuration when it is registered, so this has to come first.codecs { configureJson { explicitNulls = false } registerJson(OrderEvent::class, OrderEvent.serializer()) }final CodecRegistrybuild()Build the registryString and ByteArray are always served, whether or not anything was registered, so text and raw payloads need no ceremony. -
-
Method Detail
-
defaultContentType
final Unit defaultContentType(String contentType)
Set the default content type for auto-selection
-
registerJson
final <T extends Any> Unit registerJson(KClass<T> type, KSerializer<T> serializer)
Register a JSON codec for a specific type using kotlinx.serialization
-
register
final <T extends Any> Unit register(KClass<T> type, MessageCodec<T> codec)
Register a custom codec
-
configureJson
final CodecRegistry.Builder configureJson(Function1<JsonBuilder, Unit> block)
Adjust the Json instance that backs every JSON codec
The block starts from the registry's defaults (lenient, unknown keys ignored, defaults not encoded) and changes only what it names:
codecs { configureJson { explicitNulls = false } registerJson(OrderEvent::class, OrderEvent.serializer()) }A codec captures the configuration when it is registered, so this has to come first. Calling it after a registerJson fails loudly rather than leaving that codec behind on the previous configuration.
-
build
final CodecRegistry build()
Build the registry
String and ByteArray are always served, whether or not anything was registered, so text and raw payloads need no ceremony. An explicit registration for either type wins.
-
-
-
-