Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Try using <code>test.B$C</code> like in the following example:</p> <pre><code>&lt;mapping wildcard="false" map-null="false" map-id="test"&gt; &lt;class-a&gt;test.A&lt;/class-a&gt; &lt;class-b&gt;test.B$C&lt;/class-b&gt; &lt;field&gt; &lt;a&gt;fielda1&lt;/a&gt; &lt;b&gt;fieldc1&lt;/b&gt; &lt;/field&gt; &lt;field&gt; &lt;a&gt;fielda2&lt;/a&gt; &lt;b&gt;fieldc2&lt;/b&gt; &lt;/field&gt; &lt;/mapping&gt; </code></pre> <p>Also note that I changed the second field from <code>fielda1</code> to <code>fielda2</code>, it appeared to be a typo in your example.</p> <p><strong>Note:</strong> Because you set <code>map-id="test"</code> you must include <code>mapId</code> when you call map, like in:</p> <pre><code>B.C destObject = mapper.map(a, B.C.class, "test"); </code></pre> <hr> <p>I tested and this is working correctly:</p> <p><strong>A.java</strong></p> <pre><code>package com.test; public class A { private String fielda1; private String fielda2; public String getFielda1() { return fielda1; } public void setFielda1(String fielda1) { this.fielda1 = fielda1; } public String getFielda2() { return fielda2; } public void setFielda2(String fielda2) { this.fielda2 = fielda2; } } </code></pre> <p><strong>B.java</strong></p> <pre><code>package com.test; import java.util.List; public class B { private List&lt;C&gt; cList; public List&lt;C&gt; getcList() { return cList; } public void setcList(List&lt;C&gt; cList) { this.cList = cList; } public static class C { private String fieldc1; private String fieldc2; public String getFieldc1() { return fieldc1; } public void setFieldc1(String fieldc1) { this.fieldc1 = fieldc1; } public String getFieldc2() { return fieldc2; } public void setFieldc2(String fieldc2) { this.fieldc2 = fieldc2; } } } </code></pre> <p><strong>mapping.xml</strong></p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;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"&gt; &lt;mapping wildcard="false" map-null="false" map-id="test"&gt; &lt;class-a&gt;com.test.A&lt;/class-a&gt; &lt;class-b&gt;com.test.B$C&lt;/class-b&gt; &lt;field&gt; &lt;a&gt;fielda1&lt;/a&gt; &lt;b&gt;fieldc1&lt;/b&gt; &lt;/field&gt; &lt;field&gt; &lt;a&gt;fielda1&lt;/a&gt; &lt;b&gt;fieldc2&lt;/b&gt; &lt;/field&gt; &lt;/mapping&gt; &lt;/mappings&gt; </code></pre> <p><strong>Main.java</strong></p> <pre><code>package com.test; import java.util.ArrayList; import java.util.List; import org.dozer.DozerBeanMapper; import org.dozer.Mapper; public class Main5 { public static void main(String[] args) throws Exception { List&lt;String&gt; mappingFiles = new ArrayList&lt;String&gt;(1); mappingFiles.add("mapping.xml"); Mapper mapper = new DozerBeanMapper(mappingFiles); A a = new A(); a.setFielda1("fielda1Value"); a.setFielda2("fielda2Value"); B.C destObject = mapper.map(a, B.C.class, "test"); System.out.println(destObject.getFieldc1()); System.out.println(destObject.getFieldc2()); } } </code></pre> <p>This outputs in the console:</p> <pre><code>... fielda1Value fielda1Value </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload