Java doesn't have "null-safe" operations, like, for example Kotlin's null safety
You can either:
- catch the NPE and ignore it
- check all the references manually
- use Optional as per the other answers
- use some sort of tooling like XLST
Otherwise if you have control over the domain objects, you can redesign your classes so that the information you need is available from the top level object (make Country class do all the null checking...)