I have a converter that converts a double to a string. Before conversion, I want to format the double to a fix number of decimal place. But I noticed that it is not being invoked. Here is my method:
The two models I have has the same attribute names.
private String price; // my DTO
private Double price; // my JPA entity
This is my modelMapper bean ModelMapperConfig.java
:
public ModelMapper modelMapper() {
ModelMapper modelMapper = new ModelMapper();
modelMapper.getConfiguration().setMatchingStrategy(MatchingStrategies.STRICT);
modelMapper.getConfiguration().setAmbiguityIgnored(true);
modelMapper.addConverter(convertDoubleToString());
return modelMapper;
}
private Converter<Double, String> convertDoubleToString() {
return mappingContext -> Utility.formatDoubleToString(mappingContext.getSource());
}
The ModelMapper
is mapping my Double
to String
fine.
But it is not keeping to the formatted decimal place. Any idea what I am missing?