Class CodecRegistries



  • public final class CodecRegistries
    extends Object
    A helper class for creating and combining codecs, codec providers, and codec registries
    Since:
    3.0
    • Method Detail

      • fromCodecs

        public static CodecRegistry fromCodecs​(Codec<?>... codecs)
        Creates a CodecRegistry from the provided list of Codec instances.

        This registry can then be used alongside other registries. Typically used when adding extra codecs to existing codecs with the fromRegistries(CodecRegistry...) )} helper.

        Parameters:
        codecs - the Codec to create a registry for
        Returns:
        a CodecRegistry for the given list of Codec instances.
      • fromCodecs

        public static CodecRegistry fromCodecs​(List<? extends Codec<?>> codecs)
        Creates a CodecRegistry from the provided list of Codec instances.

        This registry can then be used alongside other registries. Typically used when adding extra codecs to existing codecs with the fromRegistries(CodecRegistry...) )} helper.

        Parameters:
        codecs - the Codec to create a registry for
        Returns:
        a CodecRegistry for the given list of Codec instances.
      • fromProviders

        public static CodecRegistry fromProviders​(CodecProvider... providers)
        Creates a CodecRegistry from the provided list of CodecProvider instances.

        The created instance can handle cycles of Codec dependencies, i.e when the construction of a Codec for class A requires the construction of a Codec for class B, and vice versa.

        Parameters:
        providers - the codec provider
        Returns:
        a CodecRegistry with the ordered list of CodecProvider instances. The registry is also guaranteed to be an instance of {code CodecProvider}, so that when one is passed to fromRegistries(CodecRegistry...) or fromRegistries(java.util.List) it will be treated as a CodecProvider and properly resolve any dependencies between registries.
      • fromProviders

        public static CodecRegistry fromProviders​(List<? extends CodecProvider> providers)
        Creates a CodecRegistry from the provided list of CodecProvider instances.

        The created instance can handle cycles of Codec dependencies, i.e when the construction of a Codec for class A requires the construction of a Codec for class B, and vice versa.

        Parameters:
        providers - the codec provider
        Returns:
        a CodecRegistry with the ordered list of CodecProvider instances. The registry is also guaranteed to be an instance of {code CodecProvider}, so that when one is passed to fromRegistries(CodecRegistry...) or fromRegistries(java.util.List) it will be treated as a CodecProvider and properly resolve any dependencies between registries.
      • fromRegistries

        public static CodecRegistry fromRegistries​(CodecRegistry... registries)
        A CodecRegistry that combines the given CodecRegistry instances into a single registry.

        The registries are checked in order until one returns a Codec for the requested Class.

        The created instance can handle cycles of Codec dependencies, i.e when the construction of a Codec for class A requires the construction of a Codec for class B, and vice versa.

        Any of the given registries that also implement CodecProvider will be treated as a CodecProvider instead of a CodecRegistry, which will ensure proper resolution of any dependencies between registries.

        Parameters:
        registries - the preferred registry for Codec lookups
        Returns:
        a CodecRegistry that combines the list of CodecRegistry instances into a single one
      • fromRegistries

        public static CodecRegistry fromRegistries​(List<? extends CodecRegistry> registries)
        A CodecRegistry that combines the given CodecRegistry instances into a single registry.

        The registries are checked in order until one returns a Codec for the requested Class.

        The created instance can handle cycles of Codec dependencies, i.e when the construction of a Codec for class A requires the construction of a Codec for class B, and vice versa.

        Any of the given registries that also implement CodecProvider will be treated as a CodecProvider instead of a CodecRegistry, which will ensure proper resolution of any dependencies between registries.

        Parameters:
        registries - the preferred registry for Codec lookups
        Returns:
        a CodecRegistry that combines the list of CodecRegistry instances into a single one