diff --git a/spring-framework-reference/src/validation.xml b/spring-framework-reference/src/validation.xml index ee33f8934d..8ccf10bb6c 100644 --- a/spring-framework-reference/src/validation.xml +++ b/spring-framework-reference/src/validation.xml @@ -1510,11 +1510,11 @@ public class PersonDtoPersonMapper implements Mapper<PersonDto, Person> {
- General-purpose SpelMapper Implementation + General-purpose Object Mapper Implementation A general purpose object-to-object mapping system exists in the org.springframework.mapping.support package. Built on the Spring Expression Language (SpEL), this system is capable of mapping between a variety of object types, including JavaBeans, Arrays, Collections, and Maps. - It can perform field-to-field, field-to-multi-field, multi-field to field, and conditional mappings. + It can perform field-to-field, field-to-multi-field, multi-field-to-field, and conditional mappings. It also can carry out type conversion and recursive mapping, which are often required with rich object models.
@@ -1609,29 +1609,30 @@ Mapper mapper = .addMapping(...) .getMapper(); ]]> - -
- Mapping between two fields with different names - - Suppose you need to map AccountDto.name to Account.fullName. - Since these two field names are not the same, the default auto-mapping rule would not apply. - Handle a requirement like this by explicitly registering a mapping rule: - - +
+
+ Mapping between two fields with different names + + Suppose you need to map AccountDto.name to Account.fullName. + Since these two field names are not the same, the default auto-mapping rule would not apply. + Handle a requirement like this by explicitly registering a mapping rule: + + - - - In the example above, the name field will be mapped to the fullName field when the mapper is executed. - No default mapping will be performed for name since an explicit mapping rule has been configured for this field. - -
-
- Mapping a single field to multiple fields - - Suppose you need to map PersonDto.name to Person.firstName and Person.lastName. - Handle a field-to-multi-field requirement like this by explicitly registering a mapping rule: - - + + In the example above, the name field will be mapped to the fullName field when the mapper is executed. + No default mapping will be performed for name since an explicit mapping rule has been configured for this field. + +
+
+ Mapping a single field to multiple fields + + Suppose you need to map PersonDto.name to Person.firstName and Person.lastName. + Handle a field-to-multi-field requirement like this by explicitly registering a mapping rule: + + () { public Person map(String name, Person person) { String[] names = name.split(" "); @@ -1640,19 +1641,19 @@ builder.addMapping("name", new Mapper() { return person; } });]]> - - - In the example above, the first part of the name field will be mapped to the firstName field and the second part will be mapped to the lastName field. - No default mapping will be performed for name since an explicit mapping rule has been configured for this field. - -
-
- Mapping multiple fields to a single field - - Suppose you need to map CreateAccountDto.activationDay and CreateAccountDto.activationTime to Account.activationDateTime. - Handle a multi-field-to-field requirement like this by explicitly registering a mapping rule: - - + + In the example above, the first part of the name field will be mapped to the firstName field and the second part will be mapped to the lastName field. + No default mapping will be performed for name since an explicit mapping rule has been configured for this field. + +
+
+ Mapping multiple fields to a single field + + Suppose you need to map CreateAccountDto.activationDay and CreateAccountDto.activationTime to Account.activationDateTime. + Handle a multi-field-to-field requirement like this by explicitly registering a mapping rule: + + () { public Account map(CreateAccountDto dto, Account account) { DateTime dateTime = ISODateTimeFormat.dateTime().parseDateTime( @@ -1661,36 +1662,35 @@ builder.addMapping(new String[] { "activationDay", "activationTime" }, new Mappe return account; } });]]> - - - In the example above, the activationDay and activationTime fields are mapped to the single activationDateTime field. - No default mapping is performed for activationDay or activationTime since an explicit mapping rule has been configured for these fields. - -
-
- Mapping conditionally - - Suppose you need to map Map.countryCode to PhoneNumber.countryCode only if the source Map contains a international phone number. - Handle conditional mapping requirements like this by explicitly registering a mapping rule: - - + + In the example above, the activationDay and activationTime fields are mapped to the single activationDateTime field. + No default mapping is performed for activationDay or activationTime since an explicit mapping rule has been configured for these fields. + +
+
+ Mapping conditionally + + Suppose you need to map Map.countryCode to PhoneNumber.countryCode only if the source Map contains a international phone number. + Handle conditional mapping requirements like this by explicitly registering a mapping rule: + + - - - In the example above, the countryCode field will only be mapped if the international field is 'true'. - international == 'true' is a boolean expression that must evaluate to true for the mapping to be executed. - No default mapping is performed for countryCode since an explicit mapping rule has been configured for this field. - -
-
- Forcing Explicit Mappings - - You can require that all mapping rules be defined explicitly by disabling the "auto mapping" feature: - - + + In the example above, the countryCode field will only be mapped if the international field is 'true'. + international == 'true' is a boolean expression that must evaluate to true for the mapping to be executed. + No default mapping is performed for countryCode since an explicit mapping rule has been configured for this field. + +
+
+ Forcing Explicit Mappings + + You can require that all mapping rules be defined explicitly by disabling the "auto mapping" feature: + + - -
+
Registering Custom Mapping Converters