java - Map an array to a complex type using Dozer -
i able map array complex type specified in 1 of answers in link. application contains more 500 classes , time consuming identify , map these 1 one. trying build generic method conversion. example , complex type array can achieved using following methods. looking ways reverse operation -
public <t> t map(object srcobj, class<?> destclass, string mapid) { if (srcobj == null) { return null; } if (srcobj.getclass().isarray()) { return (t) maparraytoarray((object[]) srcobj, destclass); } return (t) dozerbeanmapper.map(srcobj, destclass, mapid); } private object maparraytoarray(object[] srcarray, class<?> destclass) { class<?> componenttype = destclass.getcomponenttype(); object resultarray = array.newinstance(componenttype, srcarray.length); (int = 0; < srcarray.length; i++) { object resultitem = this.map(srcarray[i], componenttype); array.set(resultarray, i, resultitem); } return resultarray; }
Comments
Post a Comment