Entity-Mapper
EntityMapper is an intelligent object mapping library that automatically maps objects to Entity class.
EntityMapper depends on [Project Lombok, JODA TIME]
※EntityMaper does not need a setter and getter
Installation
1. MAVEN
<dependency>
<groupId>com.github.ckpoint</groupId>
<artifactId>entity-mapper</artifactId>
<version>0.0.1</version>
</dependency>
2. GRADLE
compile group: 'com.github.ckpoint', name: 'entity-mapper', version: '0.0.1'
Table of Contents
- 1. Create entity with entity-mapper
- 2. Update entity with entity-mapper
- 3. Handling specific field or method exceptions
Create Entity
A. extends MapEntity
- MapEntity only has automatic mapping function.
@Entity
@Getter
public class Account extends MapEntity {
private String name;
private String email;
private Long age;
private Gender gender;
}
B. extends MapBaseEntity
- MapBaseEntity has automatic mapping function and Long type id field.
@Entity
@Getter
public class Account extends MapBaseEntity{
private String name;
private String email;
private Long age;
private Gender gender;
}
C. extends MapAuditEntity
- MapAuditEntity has automatic mapping function and id, createdAt, updatedAt fields.
@Entity
@Getter
public class Account extends MapAuditEntity{
private String name;
private String email;
private Long age;
private Gender gender;
}
Update Entity
- The class inheriting EntityMapper has a function called updateFromObj
- EntityMaper does not need a setter method.
for exmaple
public void updateEntityTest() {
AccountModel hsimModel = new AccountModel();
hsimModel.setAge(25L);
hsimModel.setEmail("[email protected]");
hsimModel.setGender("MAN");
hsimModel.setName("hsim");
Account hsim = new Account();
hsim.updateFromObj(hsimModel);
}
Handling Field Method
- If you want to exclude certain fields or setter functions from automatic mapping, You just need to put the @IgnoreUpdateFromObj annotation.
for exmaple
@Entity
@Getter
public class Account extends MapAuditModel {
private String name;
private String email;
@IgnoreUpdateFromObj
private Long age;
private Gender gender;
@IgnoreUpdateFromObj
public void setAge(Long age) {
this.age = age;
}
}