Interface InstancioServiceProvider.TypeInstantiator

Enclosing interface:
InstancioServiceProvider

public static interface InstancioServiceProvider.TypeInstantiator
Provides custom instantiation logic.

An implementation of this interface can be returned via the InstancioServiceProvider.getTypeInstantiator() method.

Since:
2.11.0
  • Method Summary

    Modifier and Type
    Method
    Description
    instantiate(Class<?> type)
    Instantiates an instance of the specified type.
  • Method Details

    • instantiate

      Object instantiate(Class<?> type)
      Instantiates an instance of the specified type.

      The main use-case for implementing this interface is to provide custom instantiation logic. Instancio will attempt to instantiate classes using this method. If the object returned by this method is null, then Instancio will attempt creating an instance using internal instantiators.

      Implementations of this interface are expected only to instantiate, but not populate objects. By default, Instancio will overwrite initialised values unless Keys.OVERWRITE_EXISTING_VALUES is set to false.

      Parameters:
      type - the type to instantiate
      Returns:
      an instance of the specified type, or null to delegate instantiation to Instancio
      Throws:
      InstancioSpiException - if the returned object is not an instance of the specified type
      Since:
      2.11.0