0

I'm using annotations in a project. The thing is i'm making custom validation that (partly) depends on annotations. I'm also making own annotations, but I want to use as much as I can from the JSR 303 standard.

to check if a field 'passes' the annotation constraints i've written some methods. Example:

static boolean isNotNullValid(Field f){
    boolean valid = true;
    if(f.isAnnotationPresent(NotNull.class)){
        Object o = ObjectGetter.getFieldValue(f);
        if(o==null){
            valid = false;
        }
    }
    return valid;
}

It's quite a lot of work to do this type of validation for all annotations. Is there some method i'm missing, like .isValid() ? I mean, of course, for the standard annotations.

Thanks in advance

1 Answer 1

1

You're not supposed to code that by yourself. You should instead rely on an implementation of the JSR, for example Hibernate Validator. The Validator it implements allows getting a set of constraint violations based on the annotations on the bean.

Sign up to request clarification or add additional context in comments.

1 Comment

Hi JB, thanks for the reply. I was already affraid that I was doing too much. This helps me out a lot! Thanks!!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.