SPeL case insensitive evaluation

34 Views Asked by At

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

1

There are 1 best solutions below

0
Jens On BEST ANSWER

You can call to upper case on the attributes:

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