Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/regis-leray/fieldmapper
Inject values into an annotated object
https://github.com/regis-leray/fieldmapper
Last synced: 4 days ago
JSON representation
Inject values into an annotated object
- Host: GitHub
- URL: https://github.com/regis-leray/fieldmapper
- Owner: regis-leray
- Created: 2014-05-06T18:41:56.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2014-05-06T19:58:37.000Z (over 10 years ago)
- Last Synced: 2024-04-16T07:40:08.913Z (7 months ago)
- Language: Java
- Size: 164 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
fieldmapper [![Build Status](https://travis-ci.org/regis-leray/fieldmapper.png?branch=master)](https://travis-ci.org/regis-leray/fieldmapper)
===========Inject values into an annotated object
### Exemple with a Simple Object and Properties
Create your object with the Field annotation
```
private class User {
@Field
private String firstName;@Field(name = "name")
private String lastName;@Field(name = "birthDate", required = true)
private Date date;@Field
private List categories;
}
```Instanciate a mapper and inject values
```
Properties properties = new Properties();
properties.put("firstName", "Steeve");
properties.put("lastName", "Jobs"); // and not lastName
properties.put("birthDate", "2005-10-06"); //need to respect the pattern yyyy-MM-dd or yyyy-MM-dd HH:mm:ssa or yyyy-MM-dd HH:mm:ss.S aUser user = new User();
new FieldMapper().mapParamToObject(properties, user)```
### Exemple with a Simple Object and Param Object (holder of tree value) handle complex object (Array, List, Map)
```
Param properties = new Param("root")
.addChild("firstName", "Steeve");
.addChild("lastName", "Jobs"); // and not lastName
.addChild("birthDate", "2005-10-06"); //need to respect the pattern yyyy-MM-dd or yyyy-MM-dd HH:mm:ssa or yyyy-MM-dd HH:mm:ss.S a
.addchild(new Param("categories").addChild("cat", "apple").addChild("cat", "technology"));User user = new User();
new FieldMapper().mapParamToObject(properties, user)```