I want to make a PATCH process :
@Path("/calendrier-serveur")
@PATCH
@Produces(MediaType.APPLICATION_JSON)
public Response updateCalendrierServeur(TPosCalendrierServeur data) {
try {
TPosCalendrierServeur newData = service.updateCalendrierServeur(data);
return Response.ok(newData, MediaType.APPLICATION_JSON).build();
} catch (IllegalAccessException | InvocationTargetException e) {
LOGGER.error("Error occured while updating server calendar." + e.getStackTrace());
Payload payload = new Payload("Invalid payload.",e.getMessage());
return Response.status(Response.Status.BAD_REQUEST).entity(payload).build();
}
}
code of the service :
...
import org.apache.commons.beanutils.BeanUtilsBean;
...
@Transactional
public TPosCalendrierServeur updateCalendrierServeur(TPosCalendrierServeur data) throws IllegalAccessException, InvocationTargetException {
TPosCalendrierServeur original = calendrierServeurRepository.find("mmcUserId = ?1", data.getMmcUserId()).firstResult();
BeanUtilsBean beanUtil = new NullAwareBeanUtilsBean();
beanUtil.copyProperties(original, data);
calendrierServeurRepository.getEntityManager().merge(original);
original = calendrierServeurRepository.find("mmcUserId = ?1", data.getMmcUserId()).firstResult();
return original;
}
I debugged the data when calling the service and I get data.getAbsenceDebut() = null
before the copyProperties
, but after the copyProperties
then it remains the data of the original object from database.
So why is the property not set to null ?