1 2 package org.ksoap2.serialization; 3 4 /** 5 * A class that implements only {@link NullSoapObject#toString()}. 6 * This is useful in the case where you have a {@link SoapObject} representing an optional 7 * property in your SOAP response.<br/><br/> 8 * 9 * Example: 10 * <pre> 11 * <code> 12 * private String getAge(SoapObject person) { 13 * return person.getPropertySafely("age").toString(); 14 * } 15 * </code> 16 * </pre> 17 * <ul> 18 * <li> When the person object has an {@code age} property, the {@code age} will be returned. </li> 19 * <li> 20 * When the person object does not have an {@code age} property, 21 * {@link SoapObject#getPropertySafely(String)} 22 * returns a NullSoapObject, which in turn returns {@code null} for {@link NullSoapObject#toString()}. 23 * </li> 24 * </ul> 25 * Now it is safe to always try and get the {@code age} property (assuming your downstream 26 * code can handle {@code age}). 27 */ 28 29 public class NullSoapObject { 30 /** 31 * Overridden specifically to always return null. 32 * See the example in this class's description as to how this can be useful. 33 * 34 * @return {@code null} 35 * @see SoapObject#getPropertySafely(String) 36 */ 37 public String toString() { 38 return null; 39 } 40 } 41