Map values from .properties files to your java objects with annotations
Java
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
doc
src/util/properties
test/util/properties
.classpath
.gitignore
.project
README.md

README.md

Account.java:

class Account {
   @Property
   public Integer id;
   
   @Property
   public String name;
}

someAccount.properties:

 # A contrived example of a .properties file
 id=24
 name=Douglas Adams

Somewhere in your code:

//...

Account someAccount = new Account();

PropertiesHandler propHandler = new PropertiesHandler(someAccount);
InputStream propStream = this.getContextClassLoader()
                             .getResourceAsStream("someAccount.properties");

Properties someAccountProperties = new Properties();
someAccountProperties.load(propStream);

propHandler.applyProperties(someAccountProperties);

System.out.println(someAccount.id);   // "24"
System.out.println(someAccount.name); // "Douglas Adams"

someAccount.id = 42;

someAccountProperties = propHandler.extractProperties();

someAccountProperties.store(
   new FileWriter("someAccount.properties"),
   "An updated contrived example of a .properties file"
);

Now, someAccount.properties looks like this:

# ... TimeStamp ...
# An updated contrived example of a .properties file
id=42
name=Douglas Adams

All primitive types (and their Object companions) are supported, as well as simple arrays, sets, and lists of such types.

See the javadocs for details.