Permalink
Browse files

validation - Considering Validator components as optional components …

…[BREAKING]
  • Loading branch information...
fcamblor committed Dec 22, 2014
1 parent 312b899 commit 6b440af88d98aeea9b34fdf9ddf2e81dacca02c2
@@ -32,7 +32,7 @@ public class {{router}} extends RestxRouter {
final EntityRequestBodyReaderRegistry readerRegistry,
final EntityResponseWriterRegistry writerRegistry,
final MainStringConverter converter,
final Validator validator,
final Optional<Validator> validator,
final RestxSecurityManager securityManager) {
super(
"{{routerGroup}}", "{{router}}", new RestxRoute[] {
@@ -1,6 +1,7 @@
package restx.validation;
import com.google.common.base.Joiner;
import com.google.common.base.Optional;
import javax.validation.ConstraintViolation;
import javax.validation.Validator;
@@ -12,11 +13,14 @@
* Time: 9:57 PM
*/
public class Validations {
public static <T> T checkValid(Validator validator, T o) {
Set<ConstraintViolation<T>> violations = validator.validate(o);
if (!violations.isEmpty()) {
throw new IllegalArgumentException(Joiner.on(", ").join(violations));
public static <T> T checkValid(Optional<Validator> validator, T o) {
if(validator.isPresent()) {
Set<ConstraintViolation<T>> violations = validator.get().validate(o);
if (!violations.isEmpty()) {
throw new IllegalArgumentException(Joiner.on(", ").join(violations));
}
}
return o;
}
}

0 comments on commit 6b440af

Please sign in to comment.