TypeDescriptor.valueOf usage in favor of constants; TypedValue usage simplification
This commit is contained in:
@@ -18,7 +18,6 @@ package org.springframework.context.expression;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.springframework.core.convert.TypeDescriptor;
|
||||
import org.springframework.expression.AccessException;
|
||||
import org.springframework.expression.EvaluationContext;
|
||||
import org.springframework.expression.PropertyAccessor;
|
||||
@@ -39,7 +38,7 @@ public class MapAccessor implements PropertyAccessor {
|
||||
}
|
||||
|
||||
public TypedValue read(EvaluationContext context, Object target, String name) throws AccessException {
|
||||
return new TypedValue(((Map) target).get(name), TypeDescriptor.OBJECT);
|
||||
return new TypedValue(((Map) target).get(name));
|
||||
}
|
||||
|
||||
public boolean canWrite(EvaluationContext context, Object target, String name) throws AccessException {
|
||||
@@ -52,7 +51,7 @@ public class MapAccessor implements PropertyAccessor {
|
||||
}
|
||||
|
||||
public Class[] getSpecificTargetClasses() {
|
||||
return new Class[] {Map.class};
|
||||
return new Class[] { Map.class };
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -115,10 +115,11 @@ public abstract class AbstractPropertyBindingResult extends AbstractBindingResul
|
||||
}
|
||||
}
|
||||
if (this.conversionService != null) {
|
||||
// Try custom formatter...
|
||||
// Try custom converter...
|
||||
TypeDescriptor fieldDesc = getPropertyAccessor().getPropertyTypeDescriptor(fixedField);
|
||||
if (fieldDesc != null && this.conversionService.canConvert(fieldDesc, TypeDescriptor.STRING)) {
|
||||
return this.conversionService.convert(value, fieldDesc, TypeDescriptor.STRING);
|
||||
TypeDescriptor strDesc = TypeDescriptor.valueOf(String.class);
|
||||
if (fieldDesc != null && this.conversionService.canConvert(fieldDesc, strDesc)) {
|
||||
return this.conversionService.convert(value, fieldDesc, strDesc);
|
||||
}
|
||||
}
|
||||
return value;
|
||||
@@ -152,7 +153,7 @@ public abstract class AbstractPropertyBindingResult extends AbstractBindingResul
|
||||
TypeDescriptor td = (field != null ?
|
||||
getPropertyAccessor().getPropertyTypeDescriptor(fixedField(field)) :
|
||||
TypeDescriptor.valueOf(valueType));
|
||||
if (this.conversionService.canConvert(TypeDescriptor.STRING, td)) {
|
||||
if (this.conversionService.canConvert(TypeDescriptor.valueOf(String.class), td)) {
|
||||
editor = new ConvertingPropertyEditorAdapter(this.conversionService, td);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -95,9 +95,9 @@ public class FormattingConversionServiceTests {
|
||||
});
|
||||
formattingService.addFormatterForFieldAnnotation(new JodaDateTimeFormatAnnotationFormatterFactory());
|
||||
String formatted = (String) formattingService.convert(new LocalDate(2009, 10, 31).toDateTimeAtCurrentTime()
|
||||
.toDate(), new TypeDescriptor(Model.class.getField("date")), TypeDescriptor.STRING);
|
||||
.toDate(), new TypeDescriptor(Model.class.getField("date")), TypeDescriptor.valueOf(String.class));
|
||||
assertEquals("10/31/09", formatted);
|
||||
LocalDate date = new LocalDate(formattingService.convert("10/31/09", TypeDescriptor.STRING,
|
||||
LocalDate date = new LocalDate(formattingService.convert("10/31/09", TypeDescriptor.valueOf(String.class),
|
||||
new TypeDescriptor(Model.class.getField("date"))));
|
||||
assertEquals(new LocalDate(2009, 10, 31), date);
|
||||
}
|
||||
@@ -105,34 +105,34 @@ public class FormattingConversionServiceTests {
|
||||
@Test
|
||||
public void testPrintNull() throws ParseException {
|
||||
formattingService.addFormatterForFieldType(Number.class, new NumberFormatter());
|
||||
assertEquals("", formattingService.convert(null, TypeDescriptor.valueOf(Integer.class), TypeDescriptor.STRING));
|
||||
assertEquals("", formattingService.convert(null, TypeDescriptor.valueOf(Integer.class), TypeDescriptor.valueOf(String.class)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParseNull() throws ParseException {
|
||||
formattingService.addFormatterForFieldType(Number.class, new NumberFormatter());
|
||||
assertNull(formattingService.convert(null, TypeDescriptor.STRING, TypeDescriptor.valueOf(Integer.class)));
|
||||
assertNull(formattingService.convert(null, TypeDescriptor.valueOf(String.class), TypeDescriptor.valueOf(Integer.class)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParseEmptyString() throws ParseException {
|
||||
formattingService.addFormatterForFieldType(Number.class, new NumberFormatter());
|
||||
assertNull(formattingService.convert("", TypeDescriptor.STRING, TypeDescriptor.valueOf(Integer.class)));
|
||||
assertNull(formattingService.convert("", TypeDescriptor.valueOf(String.class), TypeDescriptor.valueOf(Integer.class)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPrintNullDefault() throws ParseException {
|
||||
assertEquals(null, formattingService.convert(null, TypeDescriptor.valueOf(Integer.class), TypeDescriptor.STRING));
|
||||
assertEquals(null, formattingService.convert(null, TypeDescriptor.valueOf(Integer.class), TypeDescriptor.valueOf(String.class)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParseNullDefault() throws ParseException {
|
||||
assertNull(formattingService.convert(null, TypeDescriptor.STRING, TypeDescriptor.valueOf(Integer.class)));
|
||||
assertNull(formattingService.convert(null, TypeDescriptor.valueOf(String.class), TypeDescriptor.valueOf(Integer.class)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParseEmptyStringDefault() throws ParseException {
|
||||
assertNull(formattingService.convert("", TypeDescriptor.STRING, TypeDescriptor.valueOf(Integer.class)));
|
||||
assertNull(formattingService.convert("", TypeDescriptor.valueOf(String.class), TypeDescriptor.valueOf(Integer.class)));
|
||||
}
|
||||
|
||||
private static class Model {
|
||||
|
||||
Reference in New Issue
Block a user