EnvBinder

open class EnvBinder(source)

Binds environment variables to an instance of a class.

This class uses an EnvReader to read environment variables and populate the fields of a given class. It supports both classes with public fields and classes with private fields and setters.

Example of usage:


public class Config {
  
  private String host;

  
  private int port;

  // Getters...
}

EnvBinder binder = new EnvBinder(EnvReader.defaultReader());
Config config = binder.bind(Config.class);

Constructors

Link copied to clipboard
constructor(envReader: EnvReader)

Functions

Link copied to clipboard
open fun <T> bind(classType: Class<T>): T
Binds environment variables to the fields of the given class.