Package org.instancio.spi
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 TypeMethodDescriptioninstantiate
(Class<?> type) Instantiates an instance of the specified type.
-
Method Details
-
instantiate
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 tofalse
.- Parameters:
type
- the type to instantiate- Returns:
- an instance of the specified
type
, ornull
to delegate instantiation to Instancio - Throws:
InstancioSpiException
- if the returned object is not an instance of the specifiedtype
- Since:
- 2.11.0
-