Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class main {
- // First we create a parser to read the validator specification which is
- // defined using the (what did you think) JSON format.
- // The validator definition is located in the "my-validator.json" resource in the
- // class path.
- JSONParser lParser =
- new JSONParser (
- main.class.getResourceAsStream("my-validator.json"));
- // We parse the validator spec and convert it into a Java representation.
- JSONObject lValidatorObject = (JSONObject) lParser.nextValue();
- // Finally we can convert our validator using the Java model.
- Validator lValidator = new JSONValidator(lValidatorObject);
- // And now that you have the validator, you can start validating your data.
- // First we create a parser to read the data.
- JSONParser lParser = new JSONParser(main.class.getResourceAsStream("data.json"));
- // We parse the datafile and convert it into a Java representation.
- JSONValue lMyData = lParser.nextValue();
- // Now we can use the validator to check on our data. We can test if the data has the
- // correct format or not.
- lValidator.validate(lMyData);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement