move jmapper to libraries-data
This commit is contained in:
@@ -0,0 +1,56 @@
|
||||
package com.baeldung.jmapper;
|
||||
|
||||
import java.time.LocalDate;
|
||||
|
||||
|
||||
public class User {
|
||||
|
||||
private long id;
|
||||
private String email;
|
||||
private LocalDate birthDate;
|
||||
|
||||
// constructors
|
||||
|
||||
public User() {
|
||||
super();
|
||||
}
|
||||
|
||||
public User(long id, String email, LocalDate birthDate) {
|
||||
super();
|
||||
this.id = id;
|
||||
this.email = email;
|
||||
this.birthDate = birthDate;
|
||||
}
|
||||
|
||||
// getters and setters
|
||||
|
||||
public long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getEmail() {
|
||||
return email;
|
||||
}
|
||||
|
||||
public void setEmail(String email) {
|
||||
this.email = email;
|
||||
}
|
||||
|
||||
public LocalDate getBirthDate() {
|
||||
return birthDate;
|
||||
}
|
||||
|
||||
public void setBirthDate(LocalDate birthDate) {
|
||||
this.birthDate = birthDate;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "User [id=" + id + ", email=" + email + ", birthDate=" + birthDate + "]";
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
package com.baeldung.jmapper;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.time.Period;
|
||||
|
||||
import com.googlecode.jmapper.annotations.JMap;
|
||||
import com.googlecode.jmapper.annotations.JMapConversion;
|
||||
|
||||
public class UserDto {
|
||||
|
||||
@JMap
|
||||
private long id;
|
||||
|
||||
@JMap("email")
|
||||
private String username;
|
||||
|
||||
@JMap("birthDate")
|
||||
private int age;
|
||||
|
||||
@JMapConversion(from={"birthDate"}, to={"age"})
|
||||
public int conversion(LocalDate birthDate){
|
||||
return Period.between(birthDate, LocalDate.now()).getYears();
|
||||
}
|
||||
|
||||
// constructors
|
||||
|
||||
public UserDto() {
|
||||
super();
|
||||
}
|
||||
|
||||
public UserDto(long id, String username, int age) {
|
||||
super();
|
||||
this.id = id;
|
||||
this.username = username;
|
||||
this.age = age;
|
||||
}
|
||||
|
||||
// getters and setters
|
||||
|
||||
public long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getUsername() {
|
||||
return username;
|
||||
}
|
||||
|
||||
public void setUsername(String username) {
|
||||
this.username = username;
|
||||
}
|
||||
|
||||
public int getAge() {
|
||||
return age;
|
||||
}
|
||||
|
||||
public void setAge(int age) {
|
||||
this.age = age;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "UserDto [id=" + id + ", username=" + username + ", age=" + age + "]";
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
package com.baeldung.jmapper;
|
||||
|
||||
import com.googlecode.jmapper.annotations.JGlobalMap;
|
||||
|
||||
@JGlobalMap
|
||||
public class UserDto1 {
|
||||
|
||||
private long id;
|
||||
private String email;
|
||||
|
||||
|
||||
// constructors
|
||||
|
||||
public UserDto1() {
|
||||
super();
|
||||
}
|
||||
|
||||
public UserDto1(long id, String email) {
|
||||
super();
|
||||
this.id = id;
|
||||
this.email = email;
|
||||
}
|
||||
|
||||
// getters and setters
|
||||
|
||||
public long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getEmail() {
|
||||
return email;
|
||||
}
|
||||
|
||||
public void setEmail(String email) {
|
||||
this.email = email;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "UserDto [id=" + id + ", email=" + email + "]";
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
package com.baeldung.jmapper.relational;
|
||||
|
||||
import com.googlecode.jmapper.annotations.JMap;
|
||||
|
||||
|
||||
public class User {
|
||||
|
||||
@JMap(classes = {UserDto1.class, UserDto2.class})
|
||||
private long id;
|
||||
|
||||
@JMap(attributes = {"username", "email"}, classes = {UserDto1.class, UserDto2.class})
|
||||
private String email;
|
||||
|
||||
// constructors
|
||||
|
||||
public User() {
|
||||
super();
|
||||
}
|
||||
|
||||
public User(long id, String email) {
|
||||
super();
|
||||
this.id = id;
|
||||
this.email = email;
|
||||
}
|
||||
|
||||
// getters and setters
|
||||
|
||||
public long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getEmail() {
|
||||
return email;
|
||||
}
|
||||
|
||||
public void setEmail(String email) {
|
||||
this.email = email;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "User [id=" + id + ", email=" + email + "]";
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
package com.baeldung.jmapper.relational;
|
||||
|
||||
|
||||
public class UserDto1 {
|
||||
|
||||
private long id;
|
||||
private String username;
|
||||
|
||||
// constructors
|
||||
|
||||
public UserDto1() {
|
||||
super();
|
||||
}
|
||||
|
||||
public UserDto1(long id, String username) {
|
||||
super();
|
||||
this.id = id;
|
||||
this.username = username;
|
||||
}
|
||||
|
||||
// getters and setters
|
||||
|
||||
public long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getUsername() {
|
||||
return username;
|
||||
}
|
||||
|
||||
public void setUsername(String username) {
|
||||
this.username = username;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "UserDto [id=" + id + ", username=" + username + "]";
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
package com.baeldung.jmapper.relational;
|
||||
|
||||
|
||||
public class UserDto2 {
|
||||
|
||||
private long id;
|
||||
private String email;
|
||||
|
||||
// constructors
|
||||
|
||||
public UserDto2() {
|
||||
super();
|
||||
}
|
||||
|
||||
public UserDto2(long id, String email) {
|
||||
super();
|
||||
this.id = id;
|
||||
this.email = email;
|
||||
}
|
||||
|
||||
// getters and setters
|
||||
|
||||
public long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getEmail() {
|
||||
return email;
|
||||
}
|
||||
|
||||
public void setEmail(String email) {
|
||||
this.email = email;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "UserDto2 [id=" + id + ", email=" + email + "]";
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
<jmapper>
|
||||
<class name="com.baeldung.jmapper.UserDto">
|
||||
<attribute name="id">
|
||||
<value name="id"/>
|
||||
</attribute>
|
||||
<attribute name="username">
|
||||
<value name="email"/>
|
||||
</attribute>
|
||||
</class>
|
||||
</jmapper>
|
||||
@@ -0,0 +1,5 @@
|
||||
<jmapper>
|
||||
<class name="com.baeldung.jmapper.UserDto1">
|
||||
<global/>
|
||||
</class>
|
||||
</jmapper>
|
||||
@@ -0,0 +1,21 @@
|
||||
<jmapper>
|
||||
<class name="com.baeldung.jmapper.relational.User">
|
||||
<attribute name="id">
|
||||
<value name="id"/>
|
||||
<classes>
|
||||
<class name="com.baeldung.jmapper.relational.UserDto1"/>
|
||||
<class name="com.baeldung.jmapper.relational.UserDto2"/>
|
||||
</classes>
|
||||
</attribute>
|
||||
<attribute name="email">
|
||||
<attributes>
|
||||
<attribute name="username"/>
|
||||
<attribute name="email"/>
|
||||
</attributes>
|
||||
<classes>
|
||||
<class name="com.baeldung.jmapper.relational.UserDto1"/>
|
||||
<class name="com.baeldung.jmapper.relational.UserDto2"/>
|
||||
</classes>
|
||||
</attribute>
|
||||
</class>
|
||||
</jmapper>
|
||||
Reference in New Issue
Block a user