sabu
sabu

Reputation: 91

SPeL case insensitive evaluation

I am using Spring expression language programmatically to evaluate certain conditions against an object

Scenario

Car car= new Car()
car.setMake("tesla");
car.setOwner(""abc);

String expresionString="( (make == 'TESLA') && owner =='ABC' )"


ExpressionParser expressionParser = new SpelExpressionParser();
Expression expression=expressionParser.parseExpression(expresionString);
Boolean result=expression.getValue(car,Boolean.class);

System.out.println("matching? "+result);

The result is false because of the case mismatch

Is there anyway to achieve case insensitive evaluation using SpeL. Also is it possible to check contains operation similar to String.contains

Upvotes: 1

Views: 128

Answers (1)

Jens
Jens

Reputation: 69470

You can call to upper case on the attributes:

String expresionString="( make.toUpperCase == 'TESLA' && owner.toUpperCase =='ABC' )"

Upvotes: 2

Related Questions