Advertisement
ILyaCyclone

Untitled

Feb 1st, 2019
1,094
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.73 KB | None | 0 0
  1. /*
  2. consume JSON structure:
  3. {
  4.    "mother": {
  5.        "name":"Susanne"
  6.    },
  7.    "kid": {
  8.        "name":"Peter"
  9.    }
  10. }
  11.  
  12. constructors and accessors are omitted
  13. */
  14.  
  15. public class MotherWithKidDTO {
  16.     private Mother mother;
  17.     private Kid kid;
  18. }
  19.  
  20. private class Mother {
  21.     private String name;
  22.     private Kid kid;
  23. }
  24.  
  25. private class Kid {
  26.     private String name;
  27.     // private Mother mother; // if needed
  28. }
  29.  
  30. @RestController
  31. public class MotherController {
  32.     @PostMapping
  33.     public Mother createMotherWithKid(@RequestBody MotherWithKidDTO motherWithKid) {
  34.         Mother mother = motherWithKid.getMother();
  35.         Kid kid = motherWithKid.getKid();
  36.         mother.setKid(kid);
  37.        
  38.         Mother created = motherService.save(mother);
  39.         return created;
  40.     }
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement