I am new on backend side and I want to use modelmapper on my project. I know how can I use modelmapper on basic level.
There is my Entity classes:
public class Content {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "id", nullable = false, unique = true)
private int id;
@ManyToOne
@JsonIgnore
@JoinColumn(name = "userId",
referencedColumnName = "userId",
foreignKey = @ForeignKey(name = "fk_content_userId"))
private User user;
@Column(name = "title")
private String title;
@Column(name = "createdDate")
private Double createdDate;
}
public class User {
@Id
@Column(name = "userId", nullable = false, unique = true)
private String userId;
@Column(name = "name")
private String name;
@Column(name = "phoneNumber")
private String phoneNumber;
@Column(name = "email")
private String email;
}
And there is my response class:
public class Response {
private String title;
private Double createdDate;
private String userId;
}
So what I want?
There is API's body:
response: {
"title": "title",
"createdDate": "1616758604",
"userId": "101010"
}
I want to convert this response to following:
Content: {
"title": "title",
"createdDate": "1616758604",
"User" : {
"userId" : "101010"
"name" : "",
"phoneNumber" : "",
"email" : ""
}
}
NOTE: I wrote "Content" in JSON format in the end. But I need it in JAVA.