-2

I have nested JAXB object which I would like to check for null.

if(message.getMpiParams() != null & 
        message.getMpiParams().getOne() != null &
        message.getMpiParams().getTwo() != null &
        message.getMpiParams().getThu() != null) { 

        ...// a lot of methods here

    }

When the inner object is empty I get always NPE. This is because XML tags are missing. How I can check for missing inner object safely without NPE? I just want to check for null object.

JAXB Object:

@XmlRootElement(name = "message")
@XmlAccessorType(XmlAccessType.FIELD)
public class Message{

    @XmlElement(name = "mpi_params")
    public MpiParams mpiParams; 

}

@XmlAccessorType(XmlAccessType.FIELD)
public class MpiParams {

    @XmlElement(name = "one")
    public String one;
}
Peter Penzov
  • 1,126
  • 134
  • 430
  • 808

1 Answers1

-2

Try changing

if(message.getMpiParams() != null

with

if(!(message.getMpiParams().equals(null))

Ithil Maethor
  • 59
  • 1
  • 7