title: Getting default message of Javax.Validation.Constraints from within a subclass?
body: <p>I have an HTML form that is submitting data to a spring post method. I've enabled validation with the javax.validation library and the @Valid tag:</p>
  
  <pre><code>public String openForm(@ModelAttribute("task")@Valid Task task,
            BindingResult result, Model model) {
            if(result.hasErrors()) {
                System.out.println("Form does not validate.");
                List&lt;ObjectError&gt; errors = result.getAllErrors();
                for(ObjectError error: errors) {
                    System.out.println(error.getDefaultMessage());
                }
             }
             return "home"; 
   }
  </code></pre>
  
  <p><code>Task</code> is the main object being binded to the form, but <code>Task</code> contains a class called <code>User</code>. User has a <code>fullName</code>. There are two fields that I am trying to validate:</p>
  
  <p><code>systemType</code> is a String within the Task object:</p>
  
  <pre><code>   @Size(min=1, message="The System Type must contain a valid option")
      private String systemType;
  </code></pre>
  
  <p><code>fullName</code> is a String within the User object: </p>
  
  <pre><code>@Size(min=1, message="A User must be selected.")
  private String fullName;
  </code></pre>
  
  <p>The validation itself is working, but what I am trying to figure out how to do is get the default message working. When I iterate through the <code>BindingResult</code> <code>result</code> for errors and print out the <code>error.getDefaultMessage()</code> the <code>systemType</code> error message works as expected. </p>
  
  <p>However, when there is a validation error with the <code>fullName</code> field, it prints:</p>
  
  <pre><code>Property 'user.fullName' threw exception; nested exception is java.lang.ArrayIndexOutOfBoundsException: 1
  </code></pre>
  
  <p>I believe this to be because it is an inner class of the main class <code>Task</code> which is what is actually being validated. I guess I could just write some logic to say that if this error comes along to just print the error message I actually want - but is there a way to go within error and get the default message I originally specified?</p>