I want to send a JSON as POST Request to insert into the database. Following is the JSON
{
"url": "https://www.tec.com",
"status":"Regular",
"Student":
{
"id": 1,
"name": "John Doe",
"age": 12
}
}
where I have the main class
Data.java
@ToString
@Setter
@Getter
@Entity
@AllArgsConstructor
@NoArgsConstructor
@Table(name = "data")
public class Data implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
public int id;
private String url;
private String status;
@ElementCollection
private Student student;
}
Student.java
@ToString
@Setter
@Getter
@AllArgsConstructor
@Entity
@NoArgsConstructor
@Table(name = "Student")
public class Student implements Serializable {
@Id
private int id;
private String name;
private int age;
}
Please tell me how to resolve this .So that the data should save in the database when I send the JSON on the above-specified format.