code: private Class<?> findBaseType(Class<?> type, Map<Class<?>, TypeSerializerFactory> factories) {
      if (factories.containsKey(type))
        return type;
  
      List<Map.Entry<Class<?>, TypeSerializerFactory>> orderedFactories = new ArrayList<>(factories.entrySet());
      Collections.reverse(orderedFactories);
  
      Optional<Map.Entry<Class<?>, TypeSerializerFactory>> optional = orderedFactories.stream()
        .filter(e -> e.getKey().isAssignableFrom(type))
        .findFirst();
      return optional.isPresent() ? optional.get().getKey() : null;
    }
docs: Finds a serializable base type for the given type in the given factories map.