private static void registerImmutableOrEmptyCollectionsWithKryo(final Kryo kryo) {
        LOGGER.trace("Registering immutable/empty collections with Kryo");

        UnmodifiableCollectionsSerializer.registerSerializers(kryo);

        ImmutableListSerializer.registerSerializers(kryo);
        kryo.register(List.of().getClass(), new ImmutableNativeJavaListSerializer());
        kryo.register(List.class, new ImmutableNativeJavaListSerializer());
        kryo.register(List.of("1").getClass(), new ImmutableNativeJavaListSerializer());
        kryo.register(List.of("1", "2").getClass(), new ImmutableNativeJavaListSerializer());
        kryo.register(List.of("1", "2", "3", "4").getClass(), new ImmutableNativeJavaListSerializer());

        ImmutableSetSerializer.registerSerializers(kryo);
        kryo.register(Set.of().getClass(), new ImmutableNativeJavaSetSerializer());
        kryo.register(Set.class, new ImmutableNativeJavaSetSerializer());
        kryo.register(Set.of("1", "2").getClass(), new ImmutableNativeJavaSetSerializer());
        kryo.register(Set.of("1", "2", "3", "4").getClass(), new ImmutableNativeJavaSetSerializer());

        ImmutableMapSerializer.registerSerializers(kryo);
        kryo.register(Map.of().getClass(), new ImmutableNativeJavaMapSerializer());
        kryo.register(Map.class, new ImmutableNativeJavaMapSerializer());
        kryo.register(Map.of("1", "2").getClass(), new ImmutableNativeJavaMapSerializer());
        kryo.register(Map.of("1", "2", "3", "4", "5", "6").getClass(), new ImmutableNativeJavaMapSerializer());

        ImmutableMultimapSerializer.registerSerializers(kryo);

        //CHECKSTYLE:OFF
        kryo.register(Collections.emptyList().getClass(), new CollectionsEmptyListSerializer());
        kryo.register(Collections.emptyMap().getClass(), new CollectionsEmptyMapSerializer());
        kryo.register(Collections.emptySet().getClass(), new CollectionsEmptySetSerializer());
        //CHECKSTYLE:ON
        
        /*
         * Can't directly access Collections classes (private class),
         * so instantiate one and do a getClass().
         */
        val singletonSet = Collections.singleton("key");
        kryo.register(singletonSet.getClass());

        val singletonMap = Collections.singletonMap("key", "value");
        kryo.register(singletonMap.getClass());

        val singletonList = Collections.singletonList("key");
        kryo.register(singletonList.getClass());

        val list = Arrays.asList("key");
        kryo.register(list.getClass(), new ArraysAsListSerializer());

        kryo.register(String.CASE_INSENSITIVE_ORDER.getClass());
    }
This is {@link CloseableKryoFactory}.

@author Misagh Moayyed
@since 5.2.0
support/cas-server-support-memcached-core/src/main/java/org/apereo/cas/memcached/kryo/CloseableKryoFactory.java