BeanUtils.copyProperties (Ignore more than one field)

0

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.

    
asked by anonymous 13.04.2018 / 15:42

1 answer

0

Actually there was a misuse on my part. The copy.Pproperties() method can ignore more than one field. To do this, simply continue entering the fields separated by commas, that is, the class meets the need of the application.

    
25.04.2018 / 04:21