Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- consume JSON structure:
- {
- "mother": {
- "name":"Susanne"
- },
- "kid": {
- "name":"Peter"
- }
- }
- constructors and accessors are omitted
- */
- public class MotherWithKidDTO {
- private Mother mother;
- private Kid kid;
- }
- private class Mother {
- private String name;
- private Kid kid;
- }
- private class Kid {
- private String name;
- // private Mother mother; // if needed
- }
- @RestController
- public class MotherController {
- @PostMapping
- public Mother createMotherWithKid(@RequestBody MotherWithKidDTO motherWithKid) {
- Mother mother = motherWithKid.getMother();
- Kid kid = motherWithKid.getKid();
- mother.setKid(kid);
- Mother created = motherService.save(mother);
- return created;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement