Skip to content

Commit

Permalink
update README
Browse files Browse the repository at this point in the history
  • Loading branch information
tvd12 committed Jun 7, 2021
1 parent 35b86bf commit a00240b
Showing 1 changed file with 36 additions and 27 deletions.
63 changes: 36 additions & 27 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,53 +9,62 @@ This project support for interact with properties file

# Code Example

**1. Map properties file to object**
**1. Read properties file**

Let's say you have a properties file "room-config.properties":
```java
Properties properties = new BaseFileReader()
.read("application.properties");
```

capacity = 1000
id = 1001
maxRoomVariablesAllowed = 30
maxSpectators = 50
**2. Read YAML file**

and you want to map it to RoomConfig object, you can do:

```java
RoomConfig room = new PropertiesMapper()
.file("room-config.properties")
.map(ExampleRoom.class);
Properties yamlProperties = new BaseFileReader()
.read("application.yaml");
```

**2. Convert an object to a map**

Sometimes you want to convert an object to a map, you can do:
**3. Read properties file with profiles**

```java
PropertiesBean map = new PropertiesBean(ClassA.class);
Properties propertiesAlpha = new MultiFileReader("alpha")
.read("application.properties");
```
or

**4. Read YAML file with profiles**

```java
PropertiesBean map = new PropertiesBean(new ClassA());
Properties propertiesAlpha = new MultiFileReader("alpha")
.read("application.yaml");
```

**3. Use annotation to map properties file to object or convert an object to a map**
**5. Map properties or YAML file to POJO**

```java
ApplicationConfig applicationConfigYaml = new PropertiesMapper()
.reader(new MultiFileReader("alpha"))
.file("application.yaml")
.map(ApplicationConfig.class);
```

Sometimes you have properties files with list of key and value, but key name is not same with field name, to map them, you can do:
***6. Use annotation to map***

```java
@PropertyWrapper
public class RoomConfig {
@Setter @Getter
protected int variablesCount;
@Setter @Getter
@Property("public")
protected boolean isPublic;
// your code
public class Config {
@Property("n")
private String name;

@Property("a")
private int age;

@Property("m")
private long money = 10;
}
```

# Motivation

Because sometimes we want to make loose coupling source code, we want to use factory design pattern, we want to map a properties file to object, convert an object to map, so I make this project for that mean
Proprties and YAML are using in a lot of framework and application, so we want to create a library support to read `.propertes` and `YAML` file and map them to `POJO` if you want

# Installation

Expand Down

0 comments on commit a00240b

Please sign in to comment.