Is it possible to configure Spring EL (SpEL) to ignore null objects in the middle of an expression

If I have an expression: obj1.obj2.obj3

And obj2 is NULL, then the expression is not executed with an exception. Is there a way to configure SpEL to return null?

+6
source share
1 answer

Should you use a safe navigation operator ?. (in your example, which would be obj1?.obj2?.obj3 ) to avoid the unpleasant NullPointerException when navigating the beans graph.

A detailed explanation and some examples can be found in chapter 6.5.15. Safe navigation operator reference

+12
source

Source: https://habr.com/ru/post/889192/


All Articles