Converter system implementation cleanup and tidying; wip
This commit is contained in:
@@ -51,19 +51,19 @@ public class SpelMapper implements Mapper<Object, Object> {
|
||||
this.autoMappingEnabled = autoMappingEnabled;
|
||||
}
|
||||
|
||||
public MappingConfiguration addMapping(String source, String target) {
|
||||
public MappingConfiguration addMapping(String sourceExpression, String targetExpression) {
|
||||
Expression sourceExp;
|
||||
try {
|
||||
sourceExp = expressionParser.parseExpression(source);
|
||||
sourceExp = expressionParser.parseExpression(sourceExpression);
|
||||
} catch (ParseException e) {
|
||||
throw new IllegalArgumentException("The mapping source '" + source
|
||||
throw new IllegalArgumentException("The mapping source '" + sourceExpression
|
||||
+ "' is not a parseable value expression", e);
|
||||
}
|
||||
Expression targetExp;
|
||||
try {
|
||||
targetExp = expressionParser.parseExpression(target);
|
||||
targetExp = expressionParser.parseExpression(targetExpression);
|
||||
} catch (ParseException e) {
|
||||
throw new IllegalArgumentException("The mapping target '" + source
|
||||
throw new IllegalArgumentException("The mapping target '" + sourceExpression
|
||||
+ "' is not a parseable property expression", e);
|
||||
}
|
||||
Mapping mapping = new Mapping(sourceExp, targetExp);
|
||||
@@ -128,7 +128,7 @@ public class SpelMapper implements Mapper<Object, Object> {
|
||||
private boolean explicitlyMapped(String field) {
|
||||
for (Mapping mapping : mappings) {
|
||||
if (mapping.source.getExpressionString().equals(field)) {
|
||||
return true;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
|
||||
@@ -14,7 +14,7 @@ public class SpelMapperTests {
|
||||
private SpelMapper mapper = new SpelMapper();
|
||||
|
||||
@Test
|
||||
public void mapAutomatic() throws MappingException {
|
||||
public void mapAutomatic() {
|
||||
Map<String, Object> source = new HashMap<String, Object>();
|
||||
source.put("name", "Keith");
|
||||
source.put("age", 31);
|
||||
@@ -45,7 +45,7 @@ public class SpelMapperTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void mapAutomaticWithExplictOverrides() throws MappingException {
|
||||
public void mapAutomaticWithExplictOverrides() {
|
||||
mapper.addMapping("test", "age");
|
||||
|
||||
Map<String, Object> source = new HashMap<String, Object>();
|
||||
@@ -63,7 +63,7 @@ public class SpelMapperTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void mapSameSourceFieldToMultipleTargets() throws MappingException {
|
||||
public void mapSameSourceFieldToMultipleTargets() {
|
||||
mapper.addMapping("test", "name");
|
||||
mapper.addMapping("test", "favoriteSport");
|
||||
|
||||
@@ -78,8 +78,36 @@ public class SpelMapperTests {
|
||||
assertEquals(0, target.age);
|
||||
assertEquals(Sport.FOOTBALL, target.favoriteSport);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void bean() {
|
||||
|
||||
}
|
||||
|
||||
|
||||
public static class Employee {
|
||||
|
||||
private String name;
|
||||
|
||||
private int age;
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public int getAge() {
|
||||
return age;
|
||||
}
|
||||
|
||||
public void setAge(int age) {
|
||||
this.age = age;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static class Person {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user