Giter Club home page Giter Club logo

propertiesmapper's Introduction

PropertiesMapper

A java library to map the values from java.util.Properties objects (most likely read from .properties files for configuration) to abitrary java Object fields using annotations and reflection.

Supported field types are String, Long, Integer, Double, Float, Boolean and their primitive equivalents.

The library has no external dependencies and can be build using ant and Java 1.7. Previous java versions down to 1.5 should work, too, but are not yet tested and thus not enabled in the project properties. Feel free to report success when compiling with Java < 1.7!

Usage example (based on a simple TinkerForge configuration):

config.properties - A .properties file containing data:

tinker.daemon.host=10.1.2.3
tinker.daemon.port=4223
tinker.display.uid=aa1
tinker.temperature.uid=bb2

TinkerConfig.java - An object to hold the property values

public class TinkerConfig {
    @Property("tinker.daemon.host")
    private String brickDaemonHost;
    
    @Property("tinker.daemon.port")
    private Integer brickDaemonPort;
    
    @Property("tinker.temperature.uid")
    private String temperaturBrickletUid;
    
    @Property("tinker.display.uid")
    private String displayBrickletUid;
...
}

To map the contents of a Properties object to an arbitrary object (for our example, loadProperties() loads the config.properties file and myAnnotatedObject is an instance of TinkerConfig):

Properties p = loadProperties(); // you still need to do this by yourself, don't care where the properties come from
PropertiesMapper.mapPropertiesToObject(p, myAnnotatedObject); // values from the p are written to myConfigObject based on the @Property annotations

To map the field values from an Object back to a Properties instance:

Properties p = new Properties();
PropertiesMapper.mapObjectToProperties(myAnnotatedObject, p);

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.