Skip to content

Commit

Permalink
add optional validation of primitives (turned off by default)
Browse files Browse the repository at this point in the history
  • Loading branch information
ohr committed Jul 15, 2015
1 parent 60f7451 commit cf9bfae
Showing 1 changed file with 20 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,25 @@ public abstract class AbstractValidator<R> implements Validator<R> {

private static final Logger LOG = LoggerFactory.getLogger(AbstractValidator.class);

private boolean validatePrimitives;

/**
* Turns validating primtives on and off (default). Note that primitive validation
* will significantly slow down the validation process.
*
* @param validatePrimitives true if primitive fields shall be validated, false if not
*/
public void setValidatePrimitives(boolean validatePrimitives) {
this.validatePrimitives = validatePrimitives;
}

/**
* @return true if primitive fields shall be validated, false if not
*/
public boolean isValidatePrimitives() {
return validatePrimitives;
}

/**
* Calls {@link #initializeHandler()} to obtain a default instance of a
* {@link ValidationExceptionHandler} before starting the validation.
Expand All @@ -78,7 +97,7 @@ public R validate(Message message, ValidationExceptionHandler<R> handler) throws
throw new NullPointerException("ValidationExceptionHandler may not be null");
}
handler.setValidationSubject(message);
// testPrimitiveRules(message, handler); TODO this slows down parser 3x
if (isValidatePrimitives()) testPrimitiveRules(message, handler);
testMessageRules(message, handler);
return handler.result();
}
Expand Down

0 comments on commit cf9bfae

Please sign in to comment.