polish
This commit is contained in:
parent
44a238616c
commit
66e6560560
|
|
@ -1564,30 +1564,14 @@ public class Account {
|
||||||
}
|
}
|
||||||
}]]></programlisting>
|
}]]></programlisting>
|
||||||
<para>
|
<para>
|
||||||
Now mapped between in the following test case:
|
Now mapped in the following service method:
|
||||||
</para>
|
</para>
|
||||||
<programlisting language="java"><![CDATA[
|
<programlisting language="java"><![CDATA[
|
||||||
@Test
|
public void createAccount(CreateAccountDto dto) {
|
||||||
public void testDefaultSpelMappingBehavior() {
|
Account account = (Account) MapperFactory.getDefaultMapper().map(dto, new Account());
|
||||||
CreateAccountDto source = new CreateAccountDto();
|
// work with the mapped account instance
|
||||||
source.setNumber("123456789");
|
}]]>
|
||||||
source.setName("Bob Sanders");
|
</programlisting>
|
||||||
AddressDto nested = new AddressDto();
|
|
||||||
nested.setStreet("123 Maple Lane");
|
|
||||||
nested.setZip("35452");
|
|
||||||
source.setAddress(nested);
|
|
||||||
|
|
||||||
Account target = new Account();
|
|
||||||
|
|
||||||
MapperFactory.getDefaultMapper().map(source, target);
|
|
||||||
|
|
||||||
assertEquals(new Long(123456789), target.getNumber();
|
|
||||||
assertEquals("Bob Sanders", target.getName());
|
|
||||||
assertEquals("123 Maple Lane", target.getAddress().getStreet());
|
|
||||||
assertEquals("35452", target.getAddress().getZip());
|
|
||||||
assertNull(target.getAddress().getCity());
|
|
||||||
assertNull(target.getAddress().getState());
|
|
||||||
}]]></programlisting>
|
|
||||||
<para>
|
<para>
|
||||||
In this example, the <literal>number</literal>, <literal>name</literal>, and <literal>address</literal> properties are automatically mapped since they are present on both the source and target objects.
|
In this example, the <literal>number</literal>, <literal>name</literal>, and <literal>address</literal> properties are automatically mapped since they are present on both the source and target objects.
|
||||||
The AccountDto's <literal>address</literal> property is a JavaBean, so its nested properties are also recursively mapped.
|
The AccountDto's <literal>address</literal> property is a JavaBean, so its nested properties are also recursively mapped.
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue