diff --git a/spring-framework-reference/src/validation.xml b/spring-framework-reference/src/validation.xml
index 301a7822cf7..703625eb5e1 100644
--- a/spring-framework-reference/src/validation.xml
+++ b/spring-framework-reference/src/validation.xml
@@ -916,8 +916,8 @@ public class MyService {
It addresses one-way conversion from one type to another and is not limited to just converting Strings.
As discussed in the previous section, a Spring Container can be configured to use this system to bind bean property values.
In addition, the Spring Expression Language (SpEL) uses this system to coerce Expression values.
- For example, when SpEL needs to coerce a Short to a Long to fullfill an
- expression.setValue() attempt, the core.convert system performs the coersion.
+ For example, when SpEL needs to coerce a Short to a Long to fulfill an
+ expression.setValue() attempt, the core.convert system performs the coercion.
Now consider the type conversion requirements of a typical UI environment such as a web or desktop application.
@@ -1467,7 +1467,7 @@ public class MyController {
There are scenarios, particularly in large message-oriented business applications, where data and object transformation is required.
For example, consider a complex Web Service where there is a separation between the data exchange model and the internal domain model used to structure business logic.
In cases like this, a general-purpose data mapping facility can be useful for automating the mapping between these disparate models.
- Spring 3 introduces such a facility built on the Spring Expression Language (SpEl).
+ Spring 3 introduces such a facility built on the Spring Expression Language (SpEL).
This facility is described in this section.
@@ -1523,12 +1523,10 @@ public class PersonDtoPersonMapper implements Mapper<PersonDto, Person> {
-
+mapper.map(aSource, aTarget);]]>
By default, SpelMapper will map the fields on the source and target that have the same names.
- If the field types differ, the mapping system will attempt a type coersion using Spring 3's type conversion system.
+ If the field types differ, the mapping system will attempt a type conversion using Spring 3's type conversion system.
Nested bean properties are mapped recursively.
Any mapping failures will trigger a MappingException to be thrown.
If there are multiple failures, they will be collected and returned in the MappingException thrown to the caller.
@@ -1546,9 +1544,7 @@ public class CreateAccountDto {
private String street;
private String zip;
}
-}
-]]>
-
+}]]>
And the following target object type:
@@ -1564,9 +1560,7 @@ public class Account {
private String state;
private String zip;
}
-}
-]]>
-
+}]]>
Used in the following test case:
@@ -1592,9 +1586,7 @@ public void testDefaultSpelMappingBehavior() {
assertEquals("35452", target.getAddress().getZip());
assertNull(target.getAddress().getCity());
assertNull(target.getAddress().getState());
-}
-]]>
-
+}]]>
In this example, the number, name, and address properties are automatically mapped since they are present on both the source and target objects.
The AccountDto's address property is a JavaBean, so its nested properties are also recursively mapped.
@@ -1611,10 +1603,7 @@ public void testDefaultSpelMappingBehavior() {
Since the two property names are not the same, default auto-mapping would never be performed.
Handle a situation like this by explicitly registering a mapping rule:
-
-
+ mapper.addMapping("name", "fullName");
In this example, 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.
@@ -1624,10 +1613,7 @@ mapper.addMapping("name", "fullName");
You can require that all mapping rules must be defined explicitly by disabling the "auto mapping" feature:
-
-
+ mapper.setAutoMappingEnabled(false);
@@ -1642,9 +1628,7 @@ mapper.addMapping("name", "fullName").setConverter() { new Converter
-
+});]]>
Ignoring Fields
@@ -1652,15 +1636,12 @@ mapper.addMapping("name", "fullName").setConverter() { new Converter
-
-
+ mapper.addMapping("name").setExclude();Registering Custom Type Converters
- You can also install Converters to coerse values of different types in a custom way.
+ You can also install Converters to convert values of different types in a custom way.
Do this by obtaining the mapper's ConverterRegistry:
() {
// do conversion
// return transformed value
}
-});
-]]>
-
+});]]>
The example Converter above will be invoked anytime a String field is mapped to a Date field.
@@ -1688,9 +1667,7 @@ mapper.addNestedMapper(new Mapper() {
// do target bean mapping here
return target;
}
-});
-]]>
-
+});]]>
The example above registers a nested Mapper that will map nested AddressDto properties to nested Address properties.
This particular nested Mapper is "hand-coded", but it could have easily been another generic SpelMapper instance.
@@ -1716,11 +1693,9 @@ public interface MappableType {
EvaluationContext getEvaluationContext(T object, ConversionService conversionService);
-}
-]]>
-
+}]]>
- To plugin your custom MappableType, inject a custom MappableTypeFactory into your SpelMapper:
+ To plug in your custom MappableType, inject a custom MappableTypeFactory into your SpelMapper:
-
+mapper.setMappableTypeFactory(factory);]]>
The Spring team encourages you to contribute any generally useful MappableType extensions back to the community.