Class CodecRegistry
-
- All Implemented Interfaces:
public final class CodecRegistryRegistry for message codecs used for serialization/deserialization
Supports pluggable serialization strategies and automatic content-type negotiation
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description public final classCodecRegistry.BuilderBuilder for CodecRegistry
-
Method Summary
Modifier and Type Method Description final <T extends Any> MessageCodec<T>codecFor(KClass<T> type)Codec registered for type, or nullwhen the type has noneLookup is exact, and deliberately has no fallback:MessageCodec<T>is erased, so a codec for some other type would pass every cast the compiler can write here and be handed back as aMessageCodec<T>that encodes and decodes something else entirely - aClassCastExceptionfrom inside the codec on publish, a value of the wrong class inFlow<T>on subscribe.final <T extends Any> MessageCodec<T>requireCodec(KClass<T> type)Get codec for a specific Kotlin type or throw IllegalArgumentExceptionThis is a convenience method for use in Flow-based APIs where throwing exceptions for missing codecs is acceptable behavior. final MessageCodec<?>codecForContentType(String contentType)Get codec by content type header -
-
Method Detail
-
codecFor
final <T extends Any> MessageCodec<T> codecFor(KClass<T> type)
Codec registered for type, or
nullwhen the type has noneLookup is exact, and deliberately has no fallback:
MessageCodec<T>is erased, so a codec for some other type would pass every cast the compiler can write here and be handed back as aMessageCodec<T>that encodes and decodes something else entirely - aClassCastExceptionfrom inside the codec on publish, a value of the wrong class inFlow<T>on subscribe.The cast is sound in the other direction: Builder.register is the only way into the map and it can only pair a
KClass<T>with aMessageCodec<T>.- Parameters:
type- The Kotlin class to get the codec for- Returns:
The codec registered for type, or
nullif there is none
-
requireCodec
final <T extends Any> MessageCodec<T> requireCodec(KClass<T> type)
Get codec for a specific Kotlin type or throw IllegalArgumentException
This is a convenience method for use in Flow-based APIs where throwing exceptions for missing codecs is acceptable behavior. For Result-based APIs, prefer using
codecFor()and handling the null case explicitly to maintain consistent error handling.- Parameters:
type- The Kotlin class to get the codec for- Returns:
The codec for the type
-
codecForContentType
final MessageCodec<?> codecForContentType(String contentType)
Get codec by content type header
-
-
-
-