Harold L. Brown
Harold L. Brown

Reputation: 9956

Compare Enums in SpEL

At Spring's @Cacheable annotation I want to specify an unless condition.

However my return value is neither a primitive type nor a Java bean, but an Enum.

How can I compare for equality with another Enum in SpEL (Spring Expression Language)?

Upvotes: 37

Views: 26738

Answers (2)

Harold L. Brown
Harold L. Brown

Reputation: 9956

#result == T(fully.qualified.path.to.AnEnum).A_VALUE

Reference here:

You can use the special T operator to specify an instance of java.lang.Class (the type).

Upvotes: 88

sorrymissjackson
sorrymissjackson

Reputation: 2705

#object.someEnumProperty.name() == 'CERTAIN_VALUE'

would work as well.

Upvotes: 30

Related Questions