Вы можете попробовать что-то вроде этого, сначала создайте запрос dto, который сопоставит json с DTO
import java.util.List;
public class RequestDTO {
private String student;
private String groupId;
private String standard;
private Boolean isPassed;
private String section;
private UserData data;
private Additional additional;
public String getStudent() {
return student;
}
public void setStudent(String student) {
this.student = student;
}
public String getGroupId() {
return groupId;
}
public void setGroupId(String groupId) {
this.groupId = groupId;
}
public String getStandard() {
return standard;
}
public void setStandard(String standard) {
this.standard = standard;
}
public Boolean getPassed() {
return isPassed;
}
public void setPassed(Boolean passed) {
isPassed = passed;
}
public String getSection() {
return section;
}
public void setSection(String section) {
this.section = section;
}
public UserData getData() {
return data;
}
public void setData(UserData data) {
this.data = data;
}
public Additional getAdditional() {
return additional;
}
public void setAdditional(Additional additional) {
this.additional = additional;
}
}
class UserData {
private String name;
private Integer age;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
class Additional{
private Personal personal;
private String state;
private Boolean Sibblings;
public Personal getPersonal() {
return personal;
}
public void setPersonal(Personal personal) {
this.personal = personal;
}
}
class Personal{
private Address address;
public Address getAddress() {
return address;
}
public void setAddress(Address address) {
this.address = address;
}
}
class Address{
private List<String> Home;
private List<String> Permanent;
private List<Language> Language;
public List<String> getHome() {
return Home;
}
public void setHome(List<String> home) {
Home = home;
}
}
enum Language{
English,French;
}
Второй создайте обработчик API, который примет этот запрос
@RestController
@RequestMapping("/api")
public class AdminController {
@RequestMapping(value = "/test", method = RequestMethod.POST)
public RequestDTO postData(@RequestBody RequestDTO requestDTO) {
logger.info("Body---->", requestDTO);
return requestDTO;
}
}
Вы можете проверить это через ниже curl
curl -X POST \
http://localhost:<PORT>/<context>/api/test \
-H 'Content-Type: application/json' \
-H 'Postman-Token: 7b66a9cf-8b69-4555-9bb2-1c186bff368d' \
-H 'cache-control: no-cache' \
-d '{
"student": "",
"groupId": "a1",
"standard": "Fifth",
"isPassed": true,
"section": "A",
"data": {
"name": "Abcd",
"age": "11"
},
"additional": {
"Personal": {
"address": {
"Home": [
"xys"
],
"Permanent": [
"xyz"
],
"Language": [
"English",
"French"
]
},
"street": "5",
"Mother": null,
"Father": null
},
"state": "xyz",
"Sibblings": true
}
}'
Я предложу вам пойти хотя бы официальный документы для лучшего понимания