public void validate ( Object response ) throws RedditParseException { // Check for null if ( response == null ) { throw new RedditParseException ( ) ; } // Check it is a JSON response if ( ! ( response instanceof JSONObject ) ) { throw new RedditParseException ( "not a JSON response" ) ; } // Cast to JSON object JSONObject jsonResponse = ( ( JSONObject ) response ) ; // Check for error if ( jsonResponse . get ( "error" ) != null ) { throw new RedditParseException ( JsonUtils . safeJsonToInteger ( jsonResponse . get ( "error" ) ) ) ; } // Check that data exists if ( jsonResponse . get ( "data" ) == null && jsonResponse . get ( "json" ) == null ) { throw new RedditParseException ( "data is missing from listing" ) ; } }
Validate that it is indeed the starting of a listing of reddit things .