How to map object properties in an Orika custom mapper? -
i tried find answer question in orika documentation no luck.
i have following classes:
public class { private string partnumber1; private string partnumber2; ... } public class b { private integer shelfnumber; private a; ... } public class bdto { private integer selfnumber; private adto somea; ... } public class adto { private string partnumber; ... }
.. , following custommapper's map objects of b objects bdo
@component public class bmapper extends custommapper<b, bdto> { @override public void mapatob(b b, bdto bdto, mappingcontext context) { super.mapatob(b, bdto, context); //??? here ??? } } @component public class amapper extends custommapper<a, adto> { @override public void mapatob(a a, adto adto, mappingcontext context) { super.mapatob(a, adto, context); adto.setpartnumber(a.getpartnumber1() + a.getpartnumber2()); } }
in client code have:
b b = new b(5, new a("100392", "100342")); bdto bdto = mapper.map(b, bdto.class);
my question is, in bmapper, correct way amapper map "a" "somea"? put differently, correct way map somea in bmapper? suspect can done through interface in mappingcontext object.
i found answer after experimentation. map property objects in main objects mapper, i.e. scenario explained above, 1 can use protected "mapperfacade" member of custommapper.
so can this:
bdto.setsomea(super.mapperfacade.map(b.geta(), adto.class));
Comments
Post a Comment