@SuppressWarnings("unchecked")
public static <T> T getGeneric(final JSONObject o, final String key, final Class<T> clazz)
throws ParseException {
if (! o.containsKey(key))
throw new ParseException("Missing JSON object member with key \"" + key + "\"");
if (o.get(key) == null)
throw new ParseException("JSON object member with key \"" + key + "\" has null value");
Object value = o.get(key);
if (! clazz.isAssignableFrom(value.getClass()))
throw new ParseException("Unexpected type of JSON object member with key \"" + key + "\"");
return (T)value;
}