ObjectBinder Example #149
-
Hi, maybe im so dump or i cant think because i have a lot of thinks in my mind but, its is possible to have some use examples or explanations of the ObjectBinder? I really want to use in my project but i dont know how to start with them. In my case i want to bind a Thanks!! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Hi! // define your class
class MyObject {
public String name = "some value";
public int id = 1;
}
// create an object
MyObject object = new MyObject();
// bind it
ObjectBinder binder = new ObjectBinder();
Config conf = binder.bind(object);
// use "conf" as a configuration, it will "read" the values from the object and "save" the values in it
conf.get("name") // "some value"
conf.set("name", "new value");
assertEquals(object.name;, "new value"); You can find an example in In your case you have a config file, therefore I think that you may not need an |
Beta Was this translation helpful? Give feedback.
Hi!
The
ObjectBinder
works like this:You can find an example in
core/src/test/java/com/electronwill/night-config/core/conversion/ObjectBinderTest.java
.In your case you have a config file, therefore I think that you may not need an
ObjectBinder