Skip field globally in ModelMapper
I am using ModelMApper to render objects from DTO to Impl - when deserializing an object. This is done in conjunction with JAxRS. When the user makes a POST / PUT request, I don't want the "id" to ever be displayed.
I need to skip the "id" field for all mappings. I don't want to do this one by one, as there are no explicit maps for all classes. How can I configure the mapping to pass all "id" fields from all DTOs into Impls mappings.
thank
source to share
One approach is to use Conditions to conditionally display (or not) the id properties. Something like this (not tested):
Condition skipIds = new Condition() {
public boolean applies(MappingContext<Object, Object> context) {
return !context.getMapping().getLastDestinationProperty().getName().equals("id");
}
};
modelMapper.getConfiguration().setPropertyCondition(skipIds);
This sets up a condition skipIds
that will be used globally for all properties so that the mapping of values ββto any destination property named "id" will be skipped.
source to share