Class CodecRegistry

  • All Implemented Interfaces:

    
    public final class CodecRegistry
    
                        

    Registry 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 class CodecRegistry.Builder

      Builder for CodecRegistry

    • Field Summary

      Fields 
      Modifier and Type Field Description
    • Constructor Summary

      Constructors 
      Constructor Description
    • Enum Constant Summary

      Enum Constants 
      Enum Constant Description
    • Method Summary

      Modifier and Type Method Description
      final <T extends Any> MessageCodec<T> codecFor(KClass<T> type) Codec registered for type, or null when 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 a MessageCodec<T> that encodes and decodes something else entirely - a ClassCastException from inside the codec on publish, a value of the wrong class in Flow<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
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

    • Method Detail

      • codecFor

         final <T extends Any> MessageCodec<T> codecFor(KClass<T> type)

        Codec registered for type, or null when the type has none

        Lookup 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 a MessageCodec<T> that encodes and decodes something else entirely - a ClassCastException from inside the codec on publish, a value of the wrong class in Flow<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 a MessageCodec<T>.

        Parameters:
        type - The Kotlin class to get the codec for
        Returns:

        The codec registered for type, or null if 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