Interface ConverterFactory

All Known Implementing Classes:
PObjectToDataObject, PObjectToMap
Functional Interface:
This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.

@FunctionalInterface public interface ConverterFactory
A factory for Converters. Used to implement conversions to generic Java classes. In such a case a single Converter does not suffice. Instead, the factory creates a new converter for every parameterization of the target type. Once created, the converter is cached for later use, and the factory is never again invoked for the same parameterized target type.

For best performance, all introspection of target types (for example using Reflection) should happen in the factory rather than the returned converters.

  • Method Summary

    Modifier and Type
    Method
    Description
    create(org.pkl.core.PClassInfo<?> sourceType, Type targetType)
    Returns a converter for the given source and target types, or Optional.empty() if the factory cannot handle the requested types.
    when(Predicate<Type> predicate)
    Returns a new factory that restricts use of this factory to target types for which the given predicate holds.
  • Method Details

    • create

      Optional<Converter<?,?>> create(org.pkl.core.PClassInfo<?> sourceType, Type targetType)
      Returns a converter for the given source and target types, or Optional.empty() if the factory cannot handle the requested types.
    • when

      default ConverterFactory when(Predicate<Type> predicate)
      Returns a new factory that restricts use of this factory to target types for which the given predicate holds.