I'm writing some code to allow dynamic property changes using the Spring Expression Language. I pass in a bean name, property name, and expression for the new value, all strings.
This works fine for properties of type string, int, boolean, and list. I'm unable to get a map property to work. I've looked at the SPeL documentation, including examples, but I don't see anything wrong with what I'm doing. The exception I get back is not helpful.
Ignoring try/catch blocks, the basic code is just this:
ExpressionParser parser = new SpelExpressionParser();
Expression parsedPropertyNameExpression = parser.parseExpression(propertyName);
SimpleEvaluationContext evalContext = SimpleEvaluationContext.forReadWriteDataBinding().build();
Object currentValue = parsedPropertyNameExpression.getValue(evalContext, bean);
parsedPropertyNameExpression.setValue(evalContext, bean, expression);
When my "expression" is "789, 0123, 345" and the property I'm setting is a List, this works perfectly fine.
However, when I'm setting a property of type Map (""), where the expression value is "{abc:'def',ghi:'jkl'}", I get the following exception:
org.springframework.core.convert.ConverterNotFoundException: No converter found capable of converting from type [java.lang.String] to type [java.util.Map<java.lang.String, java.lang.String>]
I've tried different variations of that expression string, with basically the same result.
Update:
I noticed the following SO posting: How to inject a Map using the @Value Spring Annotation? .
One of the unaccepted answers mentions defining a Map in properties and injecting that with a @Value annotation, which I would think is using a similar mechanism. How can I do that in code?