@Test public void everythingIsPerfect() { InputStream schema = this.getClass().getClassLoader().getResourceAsStream("schema.json"); InputStream data = this.getClass().getClassLoader().getResourceAsStream("data.json"); Assert.assertTrue("ERROR: Perfect match gave false instead of true", jman.isJSONValid(schema, data)); }
public boolean isJSONValid(InputStream schemaJSON, InputStream dataJSON) { JSONParser schemaParser = new JSONParser(schemaJSON); JSONParser dataParser = new JSONParser(dataJSON); try { JSONObject validatorObj = (JSONObject) schemaParser.nextValue(); Validator validator = new JSONValidator(validatorObj); JSONValue data = dataParser.nextValue(); validator.validate(data); } catch (TokenStreamException ex) { Logger.getLogger(JSONHelper.class.getName()).log(Level.SEVERE, null, ex); Log.fatal("Token stream exception"); return false; } catch (RecognitionException ex) { Logger.getLogger(JSONHelper.class.getName()).log(Level.SEVERE, null, ex); Log.fatal("Not recognized"); return false; } catch (ValidationException ex) { Logger.getLogger(JSONHelper.class.getName()).log(Level.SEVERE, null, ex); Log.fatal("Not properly validated"); return false; } return true; }
JSONHelper { public boolean isJSONValid(InputStream schemaJSON, InputStream dataJSON) { JSONParser schemaParser = new JSONParser(schemaJSON); JSONParser dataParser = new JSONParser(dataJSON); try { JSONObject validatorObj = (JSONObject) schemaParser.nextValue(); Validator validator = new JSONValidator(validatorObj); JSONValue data = dataParser.nextValue(); validator.validate(data); } catch (TokenStreamException ex) { Logger.getLogger(JSONHelper.class.getName()).log(Level.SEVERE, null, ex); Log.fatal("Token stream exception"); return false; } catch (RecognitionException ex) { Logger.getLogger(JSONHelper.class.getName()).log(Level.SEVERE, null, ex); Log.fatal("Not recognized"); return false; } catch (ValidationException ex) { Logger.getLogger(JSONHelper.class.getName()).log(Level.SEVERE, null, ex); Log.fatal("Not properly validated"); return false; } return true; } }
JSONHelper { public boolean isJSONValid(InputStream schemaJSON, InputStream dataJSON) { JSONParser schemaParser = new JSONParser(schemaJSON); JSONParser dataParser = new JSONParser(dataJSON); try { JSONObject validatorObj = (JSONObject) schemaParser.nextValue(); Validator validator = new JSONValidator(validatorObj); JSONValue data = dataParser.nextValue(); validator.validate(data); } catch (TokenStreamException ex) { Logger.getLogger(JSONHelper.class.getName()).log(Level.SEVERE, null, ex); Log.fatal("Token stream exception"); return false; } catch (RecognitionException ex) { Logger.getLogger(JSONHelper.class.getName()).log(Level.SEVERE, null, ex); Log.fatal("Not recognized"); return false; } catch (ValidationException ex) { Logger.getLogger(JSONHelper.class.getName()).log(Level.SEVERE, null, ex); Log.fatal("Not properly validated"); return false; } return true; }  }
JSONHelper { public boolean isJSONValid(InputStream schemaJSON, InputStream dataJSON) { JSONParser schemaParser = new JSONParser(schemaJSON); JSONParser dataParser = new JSONParser(dataJSON); try { JSONObject validatorObj = (JSONObject) schemaParser.nextValue(); Validator validator = new JSONValidator(validatorObj); JSONValue data = dataParser.nextValue(); validator.validate(data); } catch (TokenStreamException ex) { Logger.getLogger(JSONHelper.class.getName()).log(Level.SEVERE, null, ex); Log.fatal("Token stream exception"); return false; } catch (RecognitionException ex) { Logger.getLogger(JSONHelper.class.getName()).log(Level.SEVERE, null, ex); Log.fatal("Not recognized"); return false; } catch (ValidationException ex) { Logger.getLogger(JSONHelper.class.getName()).log(Level.SEVERE, null, ex); Log.fatal("Not properly validated"); return false; } return true; }  boolean isJSONValid(InputStream schemaJSON, InputStream dataJSON); }
JSONHelper { public boolean isJSONValid(InputStream schemaJSON, InputStream dataJSON) { JSONParser schemaParser = new JSONParser(schemaJSON); JSONParser dataParser = new JSONParser(dataJSON); try { JSONObject validatorObj = (JSONObject) schemaParser.nextValue(); Validator validator = new JSONValidator(validatorObj); JSONValue data = dataParser.nextValue(); validator.validate(data); } catch (TokenStreamException ex) { Logger.getLogger(JSONHelper.class.getName()).log(Level.SEVERE, null, ex); Log.fatal("Token stream exception"); return false; } catch (RecognitionException ex) { Logger.getLogger(JSONHelper.class.getName()).log(Level.SEVERE, null, ex); Log.fatal("Not recognized"); return false; } catch (ValidationException ex) { Logger.getLogger(JSONHelper.class.getName()).log(Level.SEVERE, null, ex); Log.fatal("Not properly validated"); return false; } return true; }  boolean isJSONValid(InputStream schemaJSON, InputStream dataJSON);  }