EntityMapper is an intelligent object mapping library that automatically maps objects to Entity class.
EntityMapper depends on [Project Lombok, JODA TIME]
<dependency>
<groupId>com.github.ckpoint</groupId>
<artifactId>entity-mapper</artifactId>
<version>0.0.1</version>
</dependency>
compile group: 'com.github.ckpoint', name: 'entity-mapper', version: '0.0.1'
- 1. Create entity with entity-mapper
- 2. Update entity with entity-mapper
- 3. Handling specific field or method exceptions
@Entity
@Getter
public class Account extends MapEntity {
private String name;
private String email;
private Long age;
private Gender gender;
}
@Entity
@Getter
public class Account extends MapBaseEntity{
private String name;
private String email;
private Long age;
private Gender gender;
}
@Entity
@Getter
public class Account extends MapAuditEntity{
private String name;
private String email;
private Long age;
private Gender gender;
}
- The class inheriting EntityMapper has a function called updateFromObj
- EntityMaper does not need a setter method.
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);
}
- If you want to exclude certain fields or setter functions from automatic mapping, You just need to put the @IgnoreUpdateFromObj annotation.
@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;
}
}