Spring EL: secure navigation with map access

I use Spring EL to pull values ​​from a rather complex set of nested maps and lists. I want to be able to use an expression like

[9]['firstSubKey']['secondSubKey']

except that it [9]['firstSubKey']can be null. I can't figure out how to use safe navigation correctly: I tried

[9]['firstSubKey']?['secondSubKey']

and

[9]['firstSubKey']?.['secondSubKey']

and both returned some sort of parsing error. I ended up getting it to work using

[9]['firstSubKey']?.get('secondSubKey')

but it seems sticky. Is there a better way or is it just a feature SpringEL doesn't have? I am using Spring 3.1.3.

, / , ? IE, 4 , , [5] null. , SpelEvaluationException.

+5
1

;

"['0']['a'] != null ? ['0']['a']['b'] : null"

"size() > 5 ? [5] : null"

+1

All Articles