如何以編程方式爲推土機設置自定義轉換器?下面的代碼不起作用:推土機5.3.2。以編程方式設置定製轉換器
自定義轉換器實現:
class ConverterImpl extends DozerConverter<A, B> {
ConverterImpl() {
super(A.class, B.class);
}
@Override
public B convertTo(A source, B destination) {
return destination;
}
@Override
public A convertFrom(B source, A destination) {
return destination;
}
}
測試代碼:
DozerBeanMapper mapper = new DozerBeanMapper();
mapper.setCustomConverters(Collections.<CustomConverter>singletonList(new ConverterImpl()));
A a = new A();
B b = mapper.map(a, A.class);
運行上面的代碼後,自定義轉換器不被調用。哪裏不對?
不是爲**域轉換器** A''或'B',而不是整個類的? – beerbajay