This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Collection<Throwable> exceptions = | |
facade.validator().validate( | |
Validation.Config.forJsonObject(objectHandler.getValue()) | |
//By calling this method the validation will be performed on the entire document, | |
//otherwise the validation will stop at the first exception thrown | |
.withCompleteValidation() | |
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
facade.validator().registerCheck( | |
//Checking whether a value in any field marked as required | |
//(e.g.: @JsonProperty(value = "answer", required = true)) is null | |
Check.forAll().checkMandatory(), | |
//Checking whether a string value in any field is empty | |
Check.forAllStringValues().execute(pathValidationContext -> { | |
if (pathValidationContext.getValue() != null && pathValidationContext.getValue().trim().equals("")) { | |
pathValidationContext.rejectValue("IS_EMPTY", "is empty"); | |
} | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Searching for the first occurrence by path suffix and convert it | |
Map<String, Object> sportAsMap = finderAndConverter.findFirstForPathEndsWith("sport"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ObjectHandler.Finder finderAndConverter = objectHandler.newValueFinderAndConverter(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Searching for the first occurrence by path suffix | |
Sport sport = finder.findFirstForPathEndsWith("sport"); | |
String option2OfSportQuestion = finder.findFirstForPathEndsWith(Path.of("sport", "q1", "options[1]")); | |
Question questionOne = finder.findForPathEquals(Path.of("quiz", "sport", "q1")); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ObjectHandler.Finder finder = objectHandler.newValueFinder(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Searching for the first occurrence by path suffix | |
ObjectHandler sportOH = finder.findFirstForPathEndsWith("sport"); | |
//Retrieving the path of the sport object ("quiz.sport") | |
String sportPath = sportOH.getPath(); | |
//Retrieving the value of the sport object | |
Sport sport = sportOH.getValue(); | |
ObjectHandler option2OfSportQuestionOH = finder.findFirstForPathEndsWith(Path.of("sport", "q1", "options[1]")); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ObjectHandler.Finder finder = objectHandler.newFinder(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Facade facade = Facade.create(); | |
//Loading the JSON object | |
ObjectHandler objectHandler = facade.newObjectHandler( | |
ObjectHandlerTest.class.getClassLoader().getResourceAsStream("quiz.json"), | |
Root.class | |
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"quiz": { | |
"sport": { | |
"q1": { | |
"question": "Which one is correct team name in NBA?", | |
"options": [ | |
"New York Bulls", | |
"Los Angeles Kings", | |
"Golden State Warriros", | |
"Huston Rocket" |
NewerOlder