Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring Expression Language - Size property on List

I am trying to use size property on List using Spring EL, which's throwing exception that size can't be found.

@Cacheable(value = "cache", unless = "#result.size > 0")
public List<Results> getResult();

Exception:

org.springframework.expression.spel.SpelEvaluationException: EL1008E:(pos 8): Field or property 'size' cannot be found on object of type 'java.util.ArrayList'
        at org.springframework.expression.spel.ast.PropertyOrFieldReference.readProperty(PropertyOrFieldReference.java:217)
        at org.springframework.expression.spel.ast.PropertyOrFieldReference.getValueInternal(PropertyOrFieldReference.java:85)
        at org.springframework.expression.spel.ast.PropertyOrFieldReference.access$000(PropertyOrFieldReference.java:43)
        at org.springframework.expression.spel.ast.PropertyOrFieldReference$AccessorLValue.getValue(PropertyOrFieldReference.java:346)
        at org.springframework.expression.spel.ast.CompoundExpression.getValueInternal(CompoundExpression.java:84)
like image 730
RaceBase Avatar asked Dec 14 '22 18:12

RaceBase


1 Answers

size resolves to List#getSize() which doesn't exist. Try with size() as follows:

@Cacheable(value = "cache", unless = "#result.size() > 0")
public List<Results> getResult();
like image 63
Predrag Maric Avatar answered Dec 17 '22 07:12

Predrag Maric