mapstruct icon indicating copy to clipboard operation
mapstruct copied to clipboard

How do we exclude fields of source in mapping?

Open reylibutan opened this issue 11 years ago • 2 comments

I skimmed over the documentation and found nothing on this one. The closest thing I found was mapstruct.unmappedTargetPolicy.

My scenario is that I have a source like this for example

public Class UserDTO {
    private String userName;
    private String password;
    private String confirmPassword;

    // getters and setters
}

But I have a target object like this

public class User {
    private String userName;
    private String password;

    // getters and setters
}

As of now, it throws an exception since it can't find a setter in the target.

reylibutan avatar Jul 05 '15 08:07 reylibutan

it throws an exception since it can't find a setter in the target

That's surprising, can you share the exact exception? Source properties not present in the target will be ignored. Only if you mapped a User to a User DTO you should get a warning about the unmapped confirmPassword which you could disable via @Mapping#ignore.

gunnarmorling avatar Jul 05 '15 08:07 gunnarmorling

Sorry this is my bad. It was Thymeleaf throwing NotReadablePropertyException.

reylibutan avatar Jul 05 '15 09:07 reylibutan