public Object tryCastObject(final BoxResourceType expectedType, final Object obj) throws BoxServerException, BoxRestException {
if (obj instanceof BoxServerError) {
throw new BoxServerException((BoxServerError) obj);
}
else if (obj instanceof BoxUnexpectedStatus) {
throw new BoxUnexpectedHttpStatusException((BoxUnexpectedStatus) obj);
}
else {
Class expectedClass = getResourceHub().getClass(expectedType);
if (expectedClass.isInstance(obj)) {
return obj;