I have two entity classes Country
and Language
having bi-directional one to many relationship.
Below are the entity classes:
You can do it in this way also. Here it doesn't create new objects. In the same object which is parsing it creates the relationship in language objects.
@PostMapping("/country")
public Country postCountryDetails(@RequestBody Country country) {
if( country.getLanguages().size() > 0 )
{
country.getLanguages().stream().forEach( countryItem -> {
countryItem.setCountry( country );
} );
}
return country;
}