I was wondering if the @Field or any other annotation supports defining which function (custom convertor) to use to create this fields value from the source object (let's say a field is based on multiple source fields for whatever reason).
Consider I have the following two classes (this is a simple example, but I did face this issue on an existing project where I was trying to plug in Selma instead of handcoded mappings)
public class Measurement {
private BigDecimal temp;
private BigDecimal humidity;
//setters and getters
}
public class MeasurementDto {
private double temperature;
private double celsiusTemp;
private double fahrenTemp;
private double humidity;
//setters and getters
}
With a mapping class like this:
@Mapper(withCustomFields = {
@Field({ "com.jatinst.selma.demo.model.MeasurementDto.temp",
"com.jatinst.selma.demo.model.Measurement.temperature" }),
@Field({ "com.jatinst.selma.demo.model.MeasurementDto.celsiustemp",
"com.jatinst.selma.demo.model.Measurement.temperature" }),
@Field({ "com.jatinst.selma.demo.model.MeasurementDto.fahrentemp",
"com.jatinst.selma.demo.model.Measurement.temperature" }) }, withCustom = { BigDecimalToDoubleMapper.class })
public interface MeasurementMapper {
public MeasurementDto getMeasurement(Measurement measure);
}
Now, there is no way I can specify that fahrenTemp = (some constant) * Measurement.temperature . I can obviously make it a different type and use a Custom Mapper, but what if the destination field was a combination of two source fields? Dozer or Orika will support this by just specifying a custom convertor at the individual field level. Is there any way to do this in Selma?