Interface InternalContainerFactoryProvider


@InternalApi public interface InternalContainerFactoryProvider
An SPI that allows populating data structures using a method.
Since:
2.0.0
  • Method Summary

    Modifier and Type
    Method
    Description
    <S, T> Function<S,T>
    getMappingFunction(Class<T> targetType, List<Class<?>> typeArguments)
    Returns a function that converts a source object of type S to the target type T.
    boolean
    isContainer(Class<?> type)
    Returns true if the given type represents a container.
  • Method Details

    • getMappingFunction

      <S, T> Function<S,T> getMappingFunction(Class<T> targetType, List<Class<?>> typeArguments)
      Returns a function that converts a source object of type S to the target type T.

      The typeArguments is provided for containers that require the type of element to be specified at construction time, for example EnumMap(Class).

      Type Parameters:
      S - source type
      T - target type
      Parameters:
      targetType - the type to be created
      typeArguments - type arguments of the source object, or an empty list if the source object is not a parameterised type
      Returns:
      conversion function, or null if not defined
    • isContainer

      boolean isContainer(Class<?> type)
      Returns true if the given type represents a container. A container is a data structure that is populated using a method, for example Collection.add() or Optional.of() If a class is marked as a container, Instancio will not inspect its fields since the object will not be populated via fields.

      Container generators should return a InternalContainerHint that specifies how the data structure should be populated.

      Parameters:
      type - to check
      Returns:
      true if the type is a container, false otherwise
      See Also: