Skip to content

Loading Bindings

A BindingLoader provides a convenient way to bulk-load bindings into a Bindings container from external sources such as Maps, POJOs, or other data structures. Instead of binding values one at a time, you can populate an entire set of bindings in a single call.

The BindingLoader is a functional interface that loads bindings into a given container:

@FunctionalInterface
public interface BindingLoader {
void load(Bindings bindings);
}

Use MapBindingLoader to load bindings from a Map<String, Object>:

Map<String, Object> data = new HashMap<>();
data.put("name", "Alice");
data.put("age", 30);
Bindings bindings = Bindings.builder().standard();
// Load the Map entries to the Bindings
bindings.load(new MapBindingLoader(), data);

Use ObjectBindingLoader to load bindings from a Java object’s properties:

public class Customer {
private String name;
private int age;
// getters and setters
}
Customer customer = new Customer("Alice", 30);
Bindings bindings = Bindings.builder().standard();
bindings.load(new FieldBindingLoader(), customer);
// Each field becomes a binding: "name" -> "Alice", "age" -> 30
bindings.load(new PropertyBindingLoader(), customer);
// Each getter becomes a binding: "name" -> "Alice", "age" -> 30