I want to merge the REST PATH payload to the 'Entity' object after getting it from a database, so that only the attributes provided in payload will be updated in entity. Hence, I want to ensure that only the attributes provided as part of patch payload will be updated safely.
I am using Spring Rest Controller with Hibernate entities.
@PatchMapping(value = "/{id}")
public Resource<DepartmentPEO> update(@PathVariable Long id,
        @RequestBody JSONObject payload) throws Exception
{
    DepartmentPEO eo = departmentService.getRow(id);
    // Have to do something to update the eo object from jsonObject.
    // Some api to update eo
    eo = departmentService.update(id, eo);
    Resource<DepartmentPEO> resource = new Resource<>(eo);
    DepartmentPEO dept = resource.getContent();
    id = dept.getDeptSeq();
    resource.add(
            linkTo(methodOn(DepartmentsRestController.class).getRow(id))
                    .withSelfRel());
    return resource;
}
Only the modified attributes will be sent as part of payload to server instead of sending all attributes.Resource(entity) will have nested list of objects (One-to-many). Am looking for the pool-proof solution for this use case and also believe this is common/basic for every rest api supported apps.
Pointing to any API to solve this would greatly appreciated!
Thank you
 
    