can I override a jsr-303 validation annotation

后端 未结 3 1226
不思量自难忘°
不思量自难忘° 2020-12-06 11:39

I have a test like below:

public class TestSizeAnnotation
{
    public static void main(String[] args)
    {
        System.out.println(Validation.buildDefau         


        
3条回答
  •  独厮守ぢ
    2020-12-06 11:48

    Overriding validation annotations is actually not supported for JSR-303. Instead annotations on overridden methods in the subclass will be applied cumulatively: From section 3.3 of the specification:

    A constraint declaration can be placed on an interface. For a given class,
    constraint declarations held on super- classes as well as interfaces are
    evaluated by the Bean Validation provider. Rules are formally described in
    Section 3.4.5.
    
    The effect of constraint declarations is cumulative. Constraints declared
    on a superclass getter will be validated along with any constraints defined
    on an overridden version of the getter according to the Java Language
    Specification visibility rules.
    

提交回复
热议问题