I'm trying to convert one type to another, using dozer mappings. I've defined some beans like these:
public class OneBean extends TwoBean {
private static final long serialVersionUID = 1L;
public OneBean() {
}
private Short idOne;
public final Short getIdOne() {
return idOne;
}
public final void setIdOne(Short idOne) {
this.idOne = idOne;
}
}
public class TwoBean extends ThreeBean{
private static final long serialVersionUID = 1L;
public TwoBean() {
}
private Short idTwo;
public final Short getIdTwo() {
return idTwo;
}
public final void setIdTwo(Short idTwo) {
this.idTwo = idTwo;
}
}
public class ThreeBean {
private static final long serialVersionUID = 1L;
public ThreeBean() {
}
private Short idThree;
public final Short getIdThree() {
return idThree;
}
public final void setIdThree(Short idThree) {
this.idThree = idThree;
}
}
public class OneTypeBean extends TwoTypeBean {
private static final long serialVersionUID = 1L;
public OneTypeBean() {
}
private Short idOne;
public final Short getIdOne() {
return idOne;
}
public final void setIdOne(Short idOne) {
this.idOne = idOne;
}
}
public class TwoTypeBean {
private static final long serialVersionUID = 1L;
public TwoTypeBean() {
}
private Short idTwo;
private Short idThree;
public final Short getIdTwo() {
return idTwo;
}
public final void setIdTwo(Short idTwo) {
this.idTwo = idTwo;
}
public final Short getIdThree() {
return idThree;
}
public final void setIdThree(Short idThree) {
this.idThree = idThree;
}
}
And the dozer file is like this:
<?xml version="1.0" encoding="UTF-8"?>
<mappings xmlns="http://dozer.sourceforge.net"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://dozer.sourceforge.net
http://dozer.sourceforge.net/schema/beanmapping.xsd">
<mapping>
<class-a>mypackage.TwoTypeBean</class-a>
<class-b>mypackage.TwoBean</class-b>
<field>
<a>idTwo</a>
<b>idTwo</b>
</field>
<field>
<a>idThree</a>
<b>idThree</b>
</field>
</mapping>
<mapping>
<class-a>mypackage.OneTypeBean</class-a>
<class-b>mypackage.OneBean</class-b>
<field>
<a>idOne</a>
<b>idOne</b>
</field>
</mapping>
</mappings>
Then, I'm trying to convert a OneBean object in OneTypeBean object, like this:
private OneTypeBean convertBeanToType(TwoBean twoBean) {
if (twoBean instanceof OneBean) {
//OneBean one = (OneBean) twoBean;
return convert(twoBean, OneTypeBean.class);
}
}
All seems ok to me (may be a problem with the hierarchy??), but, I found this error:
[#|2012-10-23T12:45:45.542+0000|INFO|sun-appserver2.1|javax.enterprise.system.stream.out|_ThreadID=32;_ThreadName=httpSSLWorkerThread-8080-4;|un.enterprise.web.connector.grizzly.DefaultProcessorTask.process(DefaultProcessorTask.java:872)
at com.sun.enterprise.web.connector.grizzly.DefaultReadTask.executeProcessorTask(DefaultReadTask.java:341)
at com.sun.enterprise.web.connector.grizzly.DefaultReadTask.doTask(DefaultReadTask.java:263)
at com.sun.enterprise.web.connector.grizzly.DefaultReadTask.doTask(DefaultReadTask.java:214)
at com.sun.enterprise.web.connector.grizzly.TaskBase.run(TaskBase.java:264)
at com.sun.enterprise.web.connector.grizzly.ssl.SSLWorkerThread.run(SSLWorkerThread.java:106)
Caused by: org.dozer.MappingException: java.lang.NoSuchMethodException: [B.<init>()
at org.dozer.util.MappingUtils.throwMappingException(MappingUtils.java:82)
at org.dozer.factory.ConstructionStrategies$ByConstructor.newInstance(ConstructionStrategies.java:261)
at org.dozer.factory.ConstructionStrategies$ByConstructor.create(ConstructionStrategies.java:245)
at org.dozer.factory.DestBeanCreator.create(DestBeanCreator.java:65)
at org.dozer.MappingProcessor.mapCustomObject(MappingProcessor.java:477)
at org.dozer.MappingProcessor.mapOrRecurseObject(MappingProcessor.java:434)
at org.dozer.MappingProcessor.mapFromFieldMap(MappingProcessor.java:330)
at org.dozer.MappingProcessor.mapField(MappingProcessor.java:276)
at org.dozer.MappingProcessor.map(MappingProcessor.java:245)
at org.dozer.MappingProcessor.processSuperTypeMapping(MappingProcessor.java:999)
at org.dozer.MappingProcessor.map(MappingProcessor.java:234)
at org.dozer.MappingProcessor.map(MappingProcessor.java:187)
at org.dozer.MappingProcessor.map(MappingProcessor.java:124)
at org.dozer.MappingProcessor.map(MappingProcessor.java:119)
at org.dozer.DozerBeanMapper.map(DozerBeanMapper.java:111)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.springframework.web.bind.annotation.support.HandlerMethodInvoker.invokeHandlerMethod(HandlerMethodInvoker.java:176)
at org.springframework.web.portlet.mvc.annotation.AnnotationMethodHandlerAdapter.invokeHandlerMethod(AnnotationMethodHandlerAdapter.java:362)
at org.springframework.web.portlet.mvc.annotation.AnnotationMethodHandlerAdapter.doHandle(AnnotationMethodHandlerAdapter.java:349)
at org.springframework.web.portlet.mvc.annotation.AnnotationMethodHandlerAdapter.handleAction(AnnotationMethodHandlerAdapter.java:283)
at org.springframework.web.portlet.DispatcherPortlet.doActionService(DispatcherPortlet.java:641)
at org.springframework.web.portlet.FrameworkPortlet.processRequest(FrameworkPortlet.java:519)
at org.springframework.web.portlet.FrameworkPortlet.processAction(FrameworkPortlet.java:460)
at com.sun.portal.portletcontainer.appengine.PortletAppEngineServlet.service(PortletAppEngineServlet.java:264)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:847)
at org.apache.catalina.core.ApplicationFilterChain.servletService(ApplicationFilterChain.java:427)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:333)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:214)
at com.sun.portal.portletcontainer.appengine.PortletAppEngineFilter.doFilter(PortletAppEngineFilter.java:105)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:246)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:214)
at org.apache.catalina.core.ApplicationDispatcher.doInvoke(ApplicationDispatcher.java:871)
at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:723)
at org.apache.catalina.core.ApplicationDispatcher.doInclude(ApplicationDispatcher.java:679)
at org.apache.catalina.core.ApplicationDispatcher.include(ApplicationDispatcher.java:594)
at com.sun.portal.portletcontainer.impl.PortletContainer.invokePAE(PortletContainer.java:819)
at com.sun.portal.portletcontainer.impl.PortletContainer.invokePAE(PortletContainer.java:694)
at com.sun.portal.portletcontainer.impl.PortletContainer.executeAction(PortletContainer.java:339)
at com.liferay.portal.portletcontainer.WindowInvoker.invokeAction(WindowInvoker.java:267)
at com.liferay.portlet.InvokerPortletImpl.processAction(InvokerPortletImpl.java:357)
at com.liferay.portal.action.LayoutAction.processPortletRequest(LayoutAction.java:591)
at com.liferay.portal.action.LayoutAction.processLayout(LayoutAction.java:419)
... 96 more
Caused by: java.lang.NoSuchMethodException: [B.<init>()
at java.lang.Class.getConstructor0(Class.java:2706)
at java.lang.Class.getDeclaredConstructor(Class.java:1985)
at org.dozer.factory.ConstructionStrategies$ByConstructor.newInstance(ConstructionStrategies.java:257)
... 146 more
|#]
I don't know what else could I do, I can't find the mistake. Any help..? Thanks!
Edit:
As I see in http://dozer.sourceforge.net/documentation/baseattributes.html , maybe I should changue my dozer to something like this...
Still not working, but working in progress...
<?xml version="1.0" encoding="UTF-8"?>
<mappings xmlns="http://dozer.sourceforge.net"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://dozer.sourceforge.net
http://dozer.sourceforge.net/schema/beanmapping.xsd">
<mapping>
<class-a>mypackage.TwoTypeBean</class-a>
<class-b>mypackage.ThreeBean</class-b>
<field>
<a>idThree</a>
<b>idThree</b>
</field>
</mapping>
<mapping>
<class-a>mypackage.OneTypeBean</class-a>
<class-b>mypackage.OneBean</class-b>
<field>
<a>idTwo</a>
<b>idTwo</b>
</field>
<field>
<a>idOne</a>
<b>idOne</b>
</field>
</mapping>
</mappings>
A similar problem was reported here, maybe it can help you out: -java.lang.NoSuchMethodException