Instancio cannot create a concrete object of an interface if no subtype class is specified. This can be solved by specifying the subtype e.g.
IFoo foo = Instancio.of(IFoo.class).subtype(all(IFoo.class), Foo.class).create();However, this is a time-consuming manual process.
An alternative is the specification of subtyping via properties file:
Properties prefixed with subtype are used to specify default implementations for abstract types, or map types to subtypes in general. This is the same mechanism as subtype mapping, but configured via properties. from https://www.instancio.org/user-guide/#overriding-settings-using-a-properties-file
The most efficient way is to provide your own provider for your own implementation of TypeResolver.
An example project of Instancio shows this can be achieved using ClassGraph on Runtime.
In this project it is shown how a TypeResolver that uses a previously compiled Jandex index may be implemented.
- Generate jandex index:
mvn package -P generate-jandex-idx -DskipTests=true- Link the custom implemented provider (e.g. JandexProvider) via file:
/src/test/resources/META-INF/services/org.instancio.spi.InstancioServiceProvider.