Skip to content

Spring formatting with Formatting from String to String and spring:eval does not work [SPR-11215] #15840

@spring-projects-issues

Description

@spring-projects-issues

Janning Vygen opened SPR-11215 and commented

Image I have an IBAN saved as a String and a @IBANFormat to trigger formatting. When I render the IBAN with spring:eval it does not work.

ExpressionUtils does not call ConversionService if both types are the same and lacking formatting the value.

Line 66 in ExpressionUtils:
{{
public static <T> T convertTypedValue(EvaluationContext context, TypedValue typedValue, Class<T> targetType) {
Object value = typedValue.getValue();
if ((targetType == null) || (value != null && ClassUtils.isAssignableValue(targetType, value))) {
return (T) value;
}
if (context != null) {
return (T) context.getTypeConverter().convertValue(value, typedValue.getTypeDescriptor(), TypeDescriptor.valueOf(targetType));
}
throw new EvaluationException("Cannot convert value '" + value + "' to type '" + targetType.getName() + "'");
}

}}

The first "if" statement is triggered because both values are Strings. No conversion and no formatting takes place.

More details at the link from StackOverflow


Affects: 4.0 GA

Reference URL: http://stackoverflow.com/questions/20542259/

Referenced from: commits 234272e, 67abeb4

Metadata

Metadata

Assignees

Labels

in: coreIssues in core modules (aop, beans, core, context, expression)type: enhancementA general enhancement

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions