}
public JSONObject append(String key, Object value) throws JSONException {
try {
Object oldVal = this.delegate.get(key);
JSONArray array = null;
if (oldVal == null) {
array = new org.apache.wink.json4j.compat.impl.ApacheJSONArrayDelegate(new org.apache.wink.json4j.JSONArray());
if (this.has(key)) {
// Add a null if the key was actually there, but just
// had value of null.
array.put((Object)null);
}
} else if (org.apache.wink.json4j.compat.impl.ApacheJSONArrayDelegate.class.isAssignableFrom(oldVal.getClass())) {
array = (JSONArray)oldVal;
} else if (org.apache.wink.json4j.JSONArray.class.isAssignableFrom(oldVal.getClass())) {
array = new org.apache.wink.json4j.compat.impl.ApacheJSONArrayDelegate((org.apache.wink.json4j.JSONArray)oldVal);
} else {
array = new org.apache.wink.json4j.compat.impl.ApacheJSONArrayDelegate(new org.apache.wink.json4j.JSONArray());
array.put(oldVal);
}
array.put(value);
return put(key,array);
} catch (Exception ex) {
JSONException jex = new JSONException(ex.getMessage());
jex.initCause(ex);
throw jex;