Skip to content

ObjectBinder Example #149

Closed Answered by TheElectronWill
josemoncab asked this question in Q&A
Discussion options

You must be logged in to vote

Hi!
The ObjectBinder works like this:

// 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 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

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@josemoncab
Comment options

Answer selected by josemoncab
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants