Alright? I'm using java and Spring-framework in a restful project, so I created the following class:
Categoria
(id, descrição, dtCadastro, dtAlteração)
In the class I am using the @PrePersist
and @PreUpdate
annotations for the date fields, so they are updated automatically when I persist a new object or when I update an existing object.
In the application I manipulate objects of this type using a DTO (CategoryDTO) with the following attributes:
(id, descrição)
Date fields have been omitted because they are fields used for auditing persisted data and are not handled by the client.
The problem is that when I use BeanUtils.copyProperties in an update endpoint it ends up generating null in the date fields, because the DTO does not have these fields.
BeanUtils.copyProperties also has a signature that lets you ignore a field, I'm using it to bypass the id in the update process.
BeanUtils.copyProperties(dto, dtoAtualizado, "id");
Is there a class that has a similar method (copy field values to another object) but allows you to ignore more than one field?
Thanks for the feedback.