Package org.instancio
Annotation Type InstancioMetaModel
-
@Target(TYPE) @Retention(SOURCE) public @interface InstancioMetaModel
This annotation provides support for generating metamodels for classes in order to avoid referencing fields as literal strings.For example, instead of:
Person person = Instancio.of(Person.class) .supply(field(Address.class, "city"), () -> "Paris") .create();
you would write:
Person person = Instancio.of(Person.class) .supply(Address_.city, () -> "Paris") .create();
Metamodels can be generated by placing
@InstancioMetaModel
annotation on a class, for instance a JUnit test class, and activating the Instancio annotation processor in your build (see documentation for Maven and Gradle examples).@InstancioMetaModel(classes = {Address.class, Person.class}) class PersonTest { // ... snip }
Note: if you need the same metamodels in multiple test classes, it is recommended to create a separate class containing the
@InstancioMetaModel
annotation, for example:@InstancioMetaModel(classes = {Address.class, Person.class}) interface MetaModelConfig { /* empty */ }
The reason for this is that duplicating the annotation for the same
'classes'
will cause metamodels for those classes to be generated more than once.
-
-
Element Detail
-
classes
Class<?>[] classes
Classes for which metamodel should be generated.- Returns:
- classes to generate metamodels for
- Default:
- {}
-
-