/** * Creates a {@code CodecRegistry} from the provided list of {@code CodecProvider} instances. * * <p>The created instance can handle cycles of {@code Codec} dependencies, i.e when the construction of a {@code Codec} for class A * requires the construction of a {@code Codec} for class B, and vice versa.</p> * * @param providers the codec provider * @return a {@code CodecRegistry} with the ordered list of {@code CodecProvider} instances. The registry is also guaranteed to be an * instance of {code CodecProvider}, so that when one is passed to {@link #fromRegistries(CodecRegistry...)} or {@link * #fromRegistries(java.util.List)} it will be treated as a {@code CodecProvider} and properly resolve any dependencies between * registries. */ public static CodecRegistry fromProviders(final List<? extends CodecProvider> providers) { return new ProvidersCodecRegistry(providers); }
/** * A {@code CodecRegistry} that combines the given {@code CodecRegistry} instances into a single registry. * * <p>The registries are checked in order until one returns a {@code Codec} for the requested {@code Class}.</p> * * <p>The created instance can handle cycles of {@code Codec} dependencies, i.e when the construction of a {@code Codec} for class A * requires the construction of a {@code Codec} for class B, and vice versa.</p> * <p>Any of the given registries that also implement {@code CodecProvider} will be treated as a {@code CodecProvider} instead of a * {@code CodecRegistry}, which will ensure proper resolution of any dependencies between registries.</p> * * @param registries the preferred registry for {@code Codec} lookups * * @return a {@code CodecRegistry} that combines the list of {@code CodecRegistry} instances into a single one */ public static CodecRegistry fromRegistries(final List<? extends CodecRegistry> registries) { List<CodecProvider> providers = new ArrayList<CodecProvider>(); for (CodecRegistry registry : registries) { providers.add(providerFromRegistry(registry)); } return new ProvidersCodecRegistry(providers); }