Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mapstruct - update existing bean and ignore a field

Tags:

mapstruct

I am updating a bean according to documentation:

@Mapper
public interface CarMapper {
    void updateCarFromDto(CarDto carDto, @MappingTarget Car car);
}

Is it possible to tell mapstruct to ignore a certain field(s) ? F.e. I don't want mapstruct to map id field from carDto to car entity, and that is what mapstruct will do if I don't define the body and skip id field mapping manually.

If it's not currently possible, is there any workaround (different than own impl.) ?

like image 473
user3529850 Avatar asked Dec 07 '25 18:12

user3529850


1 Answers

Use @Mapping( target = "id", ignore = true ).

like image 158
Sjaak Avatar answered Dec 12 '25 12:12

Sjaak



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!