I have a solution to check for NULL values retrieved from an object. However, I believe that there may be a better approach than I am here. So please suggest the best ways with a code snippet :)
I will pass my xml content to the unmarshalling method and pass the unmarshalledValues ββto a zero checking method (e.g. ValidateInputFiled)
Contents unmarshalledValues = unmarshalingContent( xml ); inputCheck = ValidateInputField( unmarshalledValues );
I have a POJO for my XML elements as follows,
@XmlRootElement( name = "contents" ) public class Contents { @XmlElement String A; @XmlElement String B; @XmlElement String C; @XmlAttribute String D; public String getA() { return A; } public String getB() { return B; } public String getC() { return C; } public String getD() { return D; } }
I defined ValidateInputFiled as below
public Boolean ValidateInputField( Contents unmarshalledValues ) { int checker = 0; Boolean listCheck = false; // Extracting unmarshalled values from xml String A= unmarshalledValues.getA(); String B= unmarshalledValues.getB(); String C = unmarshalledValues.getC(); String D= unmarshalledValues.getD(); if ( A== null || A.isEmpty() ) { checker++; } if ( B== null || B.isEmpty() ) { checker++; } if ( C== null || C.isEmpty() ) { checker++; } if ( D== null || D.isEmpty() ) { checker++; } if ( checker == 0 ) { listCheck = true; } return listCheck; }
Here I am looking to avoid NULL checking for each row value (e.g. A, B, C, D) instead, can I just do a null content check or for unmarshalledValues ββusing a collection or list?
Mad d source share