publicissapient-france/selma

Question: Could there be an annotation to ignore bean fields from mapping?

balachandra opened this issue · 0 comments

Scenario:

if i want to exclude certain common fields across beans, at present, i have to write the following on the mapper

@Mapper(withIgnoreFields = {"age", "Person.indices", "fr.xebia.selma.Person.tags"})

But if the properties are common across beans then it becomes boilerplate to do this across mappers

e.g.

Common entities/beans

User { } 
Employer { }

Beans that has refs to the common entities

Work {
    @MapperIgnore
    private User user;
    @MapperIgnore
    private Employer employer;
    private String name;
}

WorkDto {
    private String name;
}

Time {
    @MapperIgnore
    private User user;
    @MapperIgnore
    private Employer employer;
    private LocalDateTime startTime;
    private LocalDateTime endTime;
}
TimeDto {
    private LocalDateTime startTime;
    private LocalDateTime endTime;
}

Using an annotation at bean field level will help avoid additional need to ignore these fields on each mapper and looks clean. Thoughts on implementing an annotation that ignores the common fields ?