Skip to content

namuol/Property-Annotations

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

About

Map values from .properties files to your java objects with annotations

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages