ILyaCyclone icon

Untitled

ILyaCyclone | PRO | 02/01/19 06:21:24 PM UTC | 0 ⭐ | 1468 👁️ | Never ⏰ | []
Java |

730 B

|

None

|

0 👍

/

0 👎

/*
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;
    }
}

Comments

  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎