public static void recursivelyRegisterType(
            TypeInformation<?> typeInfo, SerializerConfig config, Set<Class<?>> alreadySeen) {
        if (typeInfo instanceof GenericTypeInfo) {
            GenericTypeInfo<?> genericTypeInfo = (GenericTypeInfo<?>) typeInfo;
            Serializers.recursivelyRegisterType(
                    genericTypeInfo.getTypeClass(), config, alreadySeen);
        } else if (typeInfo instanceof CompositeType) {
            List<GenericTypeInfo<?>> genericTypesInComposite = new ArrayList<>();
            getContainedGenericTypes((CompositeType<?>) typeInfo, genericTypesInComposite);
            for (GenericTypeInfo<?> gt : genericTypesInComposite) {
                Serializers.recursivelyRegisterType(gt.getTypeClass(), config, alreadySeen);
            }
        } else if (typeInfo instanceof ObjectArrayTypeInfo) {
            ObjectArrayTypeInfo<?, ?> objectArrayTypeInfo = (ObjectArrayTypeInfo<?, ?>) typeInfo;
            recursivelyRegisterType(objectArrayTypeInfo.getComponentInfo(), config, alreadySeen);
        }
    }
@Test
    void testTypeRegistration() {
        SerializerConfigImpl conf = new SerializerConfigImpl();
        Serializers.recursivelyRegisterType(ClassWithNested.class, conf, new HashSet<Class<?>>());

        KryoSerializer<String> kryo =
                new KryoSerializer<>(String.class, conf); // we create Kryo from another type.

        assertThat(kryo.getKryo().getRegistration(FromNested.class).getId()).isPositive();
        assertThat(kryo.getKryo().getRegistration(ClassWithNested.class).getId()).isPositive();
        assertThat(kryo.getKryo().getRegistration(Path.class).getId()).isPositive();

        // check if the generic type from one field is also registered (its very likely that
        // generic types are also used as fields somewhere.
        assertThat(kryo.getKryo().getRegistration(FromGeneric1.class).getId()).isPositive();
        assertThat(kryo.getKryo().getRegistration(FromGeneric2.class).getId()).isPositive();
        assertThat(kryo.getKryo().getRegistration(Node.class).getId()).isPositive();

        // register again and make sure classes are still registered
        SerializerConfigImpl conf2 = new SerializerConfigImpl();
        Serializers.recursivelyRegisterType(ClassWithNested.class, conf2, new HashSet<Class<?>>());
        KryoSerializer<String> kryo2 = new KryoSerializer<>(String.class, conf);
        assertThat(kryo2.getKryo().getRegistration(FromNested.class).getId()).isPositive();
    }