Package org.instancio
Annotation Type InstancioMetamodel
Deprecated.
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 SampleConfig { /* 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.
-
Optional Element Summary
Optional Elements
-
Element Details
-
classes
Class<?>[] classesDeprecated.Classes for which metamodel should be generated.- Returns:
- classes to generate metamodels for
- Default:
- {}
-
3.0.0
. Instead of generating metamodels, please useSelect.field(GetMethodSelector)
to target fields using method references.