Closed tokazio closed 7 years ago
Can you add mapping code and the error generated?
Full xml config:
<?xml version="1.0" encoding="UTF-8"?>
<jmapper
xmlns="https://jmapper-framework.googlecode.com"
xmlns:xsi="https://jmapper-framework.googlecode.com/svn"
xsi:noNamespaceSchemaLocation="jmapper.xsd">
<class name="net.esyo.mappersperfs.PersonDto">
<attribute name="birthDate">
<value name="birthDate"/>
</attribute>
<attribute name="aliasesList">
<value name="knownAliases"/>
</attribute>
<conversion name="firstname" to="firstName" type="DYNAMIC">
return ${source}.getName().getFirst();
</conversion>
</class>
</jmapper>
Testing it with Junit and assertJ. Direct mapped fields are ok.
No stack, but PersonDto.firstName is null
Test trace:
expected:<"Romain"> but was:
org.junit.ComparisonFailure at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) at TestsPerfs.testJMapper(TestsPerfs.java:95) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50) at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12) at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47) at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17) at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57) at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290) at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71) at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288) at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58) at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268) at org.junit.runners.ParentRunner.run(ParentRunner.java:363) at org.apache.maven.surefire.junit4.JUnit4TestSet.execute(JUnit4TestSet.java:45) at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:123) at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:104) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray(ReflectionUtils.java:164) at org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke(ProviderFactory.java:110) at org.apache.maven.surefire.booter.SurefireStarter.invokeProvider(SurefireStarter.java:175) at org.apache.maven.surefire.booter.SurefireStarter.runSuitesInProcessWhenForked(SurefireStarter.java:107) at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:68)
I don't know if
<conversion name="firstname" to="firstName" type="DYNAMIC">
return ${source}.getName().getFirst();
</conversion>
Is the right config to map Person.name.first to PersonDto.firstName
The mapping is not applied because the field "firstName" is not configured. Between attributes there isn't a field "firstName" mapped, so the conversion is ignored
ha ok! i understand now... thanks! this one works, and it's fast ;)
<?xml version="1.0" encoding="UTF-8"?>
<jmapper
xmlns="https://jmapper-framework.googlecode.com"
xmlns:xsi="https://jmapper-framework.googlecode.com/svn"
xsi:noNamespaceSchemaLocation="jmapper.xsd">
<class name="net.esyo.mappersperfs.PersonDto">
<attribute name="birthDate">
<value name="birthDate"/>
</attribute>
<attribute name="aliasesList">
<value name="knownAliases"/>
</attribute>
<attribute name="firstName">
<value name="name"/>
</attribute>
<conversion name="name.first" to="firstName" type="DYNAMIC">
return ${source}.getFirst();
</conversion>
<attribute name="lastName">
<value name="name"/>
</attribute>
<conversion name="name.last" to="lastName" type="DYNAMIC">
return ${source}.getLast();
</conversion>
</class>
</jmapper>
Name:
Person:
PersonDto:
How to map Person to PersonDto with XML ?
name.first -> firstName name.last -> lastName
This doesn't work: