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.
BindingLoader Interface
Section titled “BindingLoader Interface”The BindingLoader is a functional interface that loads bindings into a given container:
@FunctionalInterfacepublic interface BindingLoader { void load(Bindings bindings);}Loading from a Map
Section titled “Loading from a Map”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 Bindingsbindings.load(new MapBindingLoader(), data);Loading from a POJO
Section titled “Loading from a POJO”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" -> 30bindings.load(new PropertyBindingLoader(), customer);// Each getter becomes a binding: "name" -> "Alice", "age" -> 30