protected JsonObject readJsonFromContent ( Object contentToValidate ) throws Exception { if ( contentToValidate == null ) { throw new Exception ( "Provided content is null so cannot be validated." ) ; } JsonObject obj = null ; try { String responseText = WebResponseUtils . getResponseText ( contentToValidate ) ; obj = Json . createReader ( new StringReader ( responseText ) ) . readObject ( ) ; } catch ( Exception e ) { throw new Exception ( "Failed to read JSON data from the provided content. The exception was [" + e + "]. The content to validate was: [" + contentToValidate + "]." ) ; } return obj ; }
Attempts to read the response text in the provided object as a JSON string and convert it to its corresponding JsonObject representation . Extending classes should override this method if they do not expect the content to be a pure JSON string . For example if the provided object is an instance of WebResponse whose response text includes other non - JSON information the extending expectation class should override this method to extract the appropriate JSON data .