use of org.apache.tapestry5.json.exceptions.JSONTypeMismatchException in project tapestry-5 by apache.
the class JSONObject method append.
/**
* Appends values to the array mapped to {@code name}. A new {@link JSONArray}
* mapping for {@code name} will be inserted if no mapping exists. If the existing
* mapping for {@code name} is not a {@link JSONArray}, a {@link RuntimeException}
* will be thrown.
*
* @param name The name of the array to which the value should be appended.
* @param value The value to append.
* @return this object.
* @throws JSONTypeMismatchException if {@code name} is {@code null} or if the mapping for
* {@code name} is non-null and is not a {@link JSONArray}.
*/
public JSONObject append(String name, Object value) {
JSON.testValidity(value);
Object current = nameValuePairs.get(checkName(name));
final JSONArray array;
if (current instanceof JSONArray) {
array = (JSONArray) current;
} else if (current == null) {
JSONArray newArray = new JSONArray();
nameValuePairs.put(name, newArray);
array = newArray;
} else {
throw new JSONTypeMismatchException("JSONObject[\"" + name + "\"]", JSONType.ARRAY, current.getClass());
}
array.checkedPut(value);
return this;
}
Aggregations