I use Jersey to provide REST API. I wrote controller, which map request to entity:
@POST
@Path("register")
@Consumes("application/json")
@Produces("application/json")
public Response UserRegistration(User UserData)
{
}
It works fine for simple json like:
{
"email":"email@email.pl",
"name":"Name",
"surname":"surname"
}
and entity:
public class User {
public User() {}
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id",unique = true)
private int id;
@Column(name = "name")
private String name;
@Column(name = "surname")
private String surname;
@Column(name = "email", unique = true)
private String email;
//getters
// setters
}
How can I map JSON array like:
{
"email":"email@email.pl",
"name":"Name",
"surname":"surname"
"reqData":{
"ip":44.44.44.44}
}
To two entites? First entity: user (shown above) and entity reqData:
public class RegistrationData {
public RegistrationData(){};
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id", unique = true)
private int id;
@Column(name = "ip")
private int ip;
I have of course One to One relationship, but it is not important here(I think). I hope my question is understandable. Thanks for help.