Reputation: 1081
I've just noticed my two classes had slightly different types for the same property, double vs Double. As a result null Double would be automatically be converted to 0 double. Now I see I could even have the same property defined as a String on one side without any validation errors being raised.
Is there a configuration in ModelMapper to require strict type mapping between properties, ie. fail validation if the types are not exactly the same.
Example:
public class MyCarDto {
public double numberOfWheels;
}
public class MyCarDao {
public Double numberOfWheels;
}
public class MyCarMapper {
private final ModelMapper modelMapper;
public MyCarMapper() {
modelMapper = new ModelMapper();
modelMapper.typeMap(MyCarDto.class, MyCarDao.class);
// should throw an exception saying property numberOfWheels should be exact same type
modelMapper.validate();
}
}
Upvotes: 0
Views: 215
Reputation: 89139
You can configure full type matching.
modelMapper.getConfiguration().setFullTypeMatchingRequired(true);
Upvotes: 1