Package org.instancio

Annotation Type InstancioMetamodel


@Deprecated @Target(TYPE) @Retention(SOURCE) public @interface InstancioMetamodel
Deprecated.
this feature is deprecated and will be removed in version 3.0.0. Instead of generating metamodels, please use Select.field(GetMethodSelector) to target fields using method references.
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
    Modifier and Type
    Optional Element
    Description
    Class<?>[]
    Deprecated.
    Classes for which metamodel should be generated.
  • Element Details

    • classes

      Class<?>[] classes
      Deprecated.
      Classes for which metamodel should be generated.
      Returns:
      classes to generate metamodels for
      Default:
      {}