Interface GeneratorProvider


public interface GeneratorProvider
A Service Provider Interface for mapping classes to custom Generator implementations.

Implementations of this class can be registered by placing a file named org.instancio.spi.GeneratorProvider under /META-INF/services. The file must contain the fully-qualified name of the implementing class.

For example, the following sample implementation:


 package com.example;

 // imports omitted

 public class SampleGeneratorProvider implements GeneratorProvider {

     @Override
     public Map<Class<?>, Generator<?>> getGenerators() {
         Map<Class<?>, Generator<?>> map = new HashMap<>();
         map.put(Book.class, new BookGenerator());
         map.put(Author.class, new AuthorGenerator());
         return map;
     }
 }
 

can be registered by creating a file /META-INF/services/org.instancio.spi.GeneratorProvider containing the following line:


 com.example.SampleGeneratorProvider
 
Since:
1.2.0
See Also:
  • Method Details

    • getGenerators

      Map<Class<?>,Generator<?>> getGenerators(GeneratorContext context)
      Provides a map of generators to register.
      Parameters:
      context - generator context
      Returns:
      class to generator mapping
      Since:
      1.2.0