}
ParseGetCommand command = new ParseGetCommand(endPoint);
query.remove("className");
command.setData(query);
ParseResponse response = command.perform();
List<T> results = null;
if(!response.isFailed()) {
if(response.getJsonObject() == null) {
LOGGER.debug("Empty response.");
throw response.getException();
}
try {
JSONObject json = response.getJsonObject();
JSONArray objs = json.getJSONArray("results");
if(objs.length() == 0) {
return null;
}
if(trace) {
strTrace = json.getString("trace");
if(LOGGER.isDebugEnabled()) {
LOGGER.debug(strTrace);
}
}
results = new ArrayList<T>();
for(int i = 0; i < objs.length(); i++) {
Class<?> clazz = ParseRegistry.getParseClass(getClassName());
if(clazz != null) {
T po = (T) clazz.newInstance();
JSONObject obj = (JSONObject) objs.get(i);
/*
We disable some checks while setting data in objects during fetch because
those checks are useful only when setting data from client
code. The "true" argument disables such checks.
*/
po.setData(obj, true);
results.add((T) po);
}
else {
ParseObject po = new ParseObject(getClassName());
JSONObject obj = (JSONObject) objs.get(i);
// see above for the "true" argument
po.setData(obj, true);
results.add((T) po);
}
}
return results;
}
catch (JSONException e) {
LOGGER.error(
"Although Parse reports object successfully saved, the response was invalid.",
e);
throw new ParseException(
ParseException.INVALID_JSON,
"Although Parse reports object successfully saved, the response was invalid.",
e);
} catch (InstantiationException e) {
LOGGER.error("Error while instantiating class. Did you register your subclass?", e);
throw new ParseException(
ParseException.INVALID_JSON,
"Although Parse reports object successfully saved, the response was invalid.",
e);
} catch (IllegalAccessException e) {
LOGGER.error("Error while instantiating class. Did you register your subclass?",e);
throw new ParseException(
ParseException.INVALID_JSON,
"Although Parse reports object successfully saved, the response was invalid.",
e);
}
}
else {
LOGGER.debug("Request failed.");
throw response.getException();
}
}