java - Dozer unable to map Collection<Interface> member -
i have object contains collection:
public class wrapper { private collection<base> bases = new linkedlist<base>(); public collection<base> getbases() {return bases;} public void setbases(final collection<base> bases) {this.bases = bases;} }
the implementations of interface quite simple:
public class baseone implements base { } public class basetwo implements base { }
when run simple test:
@test public void testcopyother() { final wrapper wrapper = new wrapper(); wrapper.getbases().add(new baseone()); final wrapper copy = dozer.map(wrapper, wrapper.class); }
i exception:
org.dozer.mappingexception: java.lang.nosuchmethodexception: com.usamp.biddingtool.model.service.impl.base.<init>() @ org.dozer.util.mappingutils.throwmappingexception(mappingutils.java:82) @ org.dozer.factory.constructionstrategies$byconstructor.newinstance(constructionstrategies.java:261) @ org.dozer.factory.constructionstrategies$byconstructor.create(constructionstrategies.java:245) @ org.dozer.factory.destbeancreator.create(destbeancreator.java:65) @ org.dozer.mappingprocessor.mapcustomobject(mappingprocessor.java:489) @ org.dozer.mappingprocessor.maporrecurseobject(mappingprocessor.java:446) @ org.dozer.mappingprocessor.addorupdatetolist(mappingprocessor.java:776) @ org.dozer.mappingprocessor.addorupdatetolist(mappingprocessor.java:850) @ org.dozer.mappingprocessor.maplisttolist(mappingprocessor.java:686) @ org.dozer.mappingprocessor.mapcollection(mappingprocessor.java:541) @ org.dozer.mappingprocessor.maporrecurseobject(mappingprocessor.java:434) @ org.dozer.mappingprocessor.mapfromfieldmap(mappingprocessor.java:342) @ org.dozer.mappingprocessor.mapfield(mappingprocessor.java:288) @ org.dozer.mappingprocessor.map(mappingprocessor.java:248) @ org.dozer.mappingprocessor.map(mappingprocessor.java:197) @ org.dozer.mappingprocessor.map(mappingprocessor.java:187) @ org.dozer.mappingprocessor.map(mappingprocessor.java:124) @ org.dozer.mappingprocessor.map(mappingprocessor.java:119) @ org.dozer.dozerbeanmapper.map(dozerbeanmapper.java:120) @ com.usamp.biddingtool.model.service.impl.dozertest.testcopyother(dozertest.java:52) @ sun.reflect.nativemethodaccessorimpl.invoke0(native method) @ sun.reflect.nativemethodaccessorimpl.invoke(nativemethodaccessorimpl.java:57) @ sun.reflect.delegatingmethodaccessorimpl.invoke(delegatingmethodaccessorimpl.java:43) @ org.junit.runners.model.frameworkmethod$1.runreflectivecall(frameworkmethod.java:47) @ org.junit.internal.runners.model.reflectivecallable.run(reflectivecallable.java:12) @ org.junit.runners.model.frameworkmethod.invokeexplosively(frameworkmethod.java:44) @ org.junit.internal.runners.statements.invokemethod.evaluate(invokemethod.java:17) @ org.springframework.test.context.junit4.statements.runbeforetestmethodcallbacks.evaluate(runbeforetestmethodcallbacks.java:74) @ org.springframework.test.context.junit4.statements.runaftertestmethodcallbacks.evaluate(runaftertestmethodcallbacks.java:83) @ org.springframework.test.context.junit4.statements.springrepeat.evaluate(springrepeat.java:72) @ org.springframework.test.context.junit4.springjunit4classrunner.runchild(springjunit4classrunner.java:231) @ org.springframework.test.context.junit4.springjunit4classrunner.runchild(springjunit4classrunner.java:88) @ org.junit.runners.parentrunner$3.run(parentrunner.java:238) @ org.junit.runners.parentrunner$1.schedule(parentrunner.java:63) @ org.junit.runners.parentrunner.runchildren(parentrunner.java:236) @ org.junit.runners.parentrunner.access$000(parentrunner.java:53) @ org.junit.runners.parentrunner$2.evaluate(parentrunner.java:229) @ org.springframework.test.context.junit4.statements.runbeforetestclasscallbacks.evaluate(runbeforetestclasscallbacks.java:61) @ org.springframework.test.context.junit4.statements.runaftertestclasscallbacks.evaluate(runaftertestclasscallbacks.java:71) @ org.junit.runners.parentrunner.run(parentrunner.java:309) @ org.springframework.test.context.junit4.springjunit4classrunner.run(springjunit4classrunner.java:174) @ org.junit.runner.junitcore.run(junitcore.java:160) @ com.intellij.junit4.junit4ideatestrunner.startrunnerwithargs(junit4ideatestrunner.java:77) @ com.intellij.rt.execution.junit.junitstarter.preparestreamsandstart(junitstarter.java:195) @ com.intellij.rt.execution.junit.junitstarter.main(junitstarter.java:63) @ sun.reflect.nativemethodaccessorimpl.invoke0(native method) @ sun.reflect.nativemethodaccessorimpl.invoke(nativemethodaccessorimpl.java:57) @ com.intellij.rt.execution.application.appmain.main(appmain.java:120)
so, seems dozer trying create instance of actual type being used in collection while type interface. since interfaces cannot instantiated error produced.
i have seen others ask question, not specific answer. there solutions issue?
thanks. -ap_
you have give hint dozer implementation of base. otherwise try instantiate interface , not possible. <mapping> <class-a>wrapper</class-a> <class-b>wrapper</class-b> <field> <a>bases</a> <b>bases</b> <a-hint>baseone,basetwo</a-hint> <b-hint>baseone,basetwo</b-hint> </field> </mapping>
http://dozer.sourceforge.net/documentation/baseattributes.html
alternative (update): <mapping> <class-a>baseone</class-a> <class-b>baseone</class-b> </mapping> <mapping> <class-a>basetwo</class-a> <class-b>basetwo</class-b> </mapping>
Comments
Post a Comment