title: How add error code to ConstraintValidator in Spring?
body: <p>I implemented my own annotation and ConstraintValidator (JSR-303). During the validation process I want to create different error codes:</p>
  
  <pre><code>public class SomeValidator implements ConstraintValidator&lt;ConstraintAnnotation,SomeObject&gt; {
  
      @Override
      public void initialize (ConstraintAnnotation constraintAnnotation) {
      }
      @Override
      public boolean isValid (SomeObject some, ConstraintValidatorContext context) {
          int parameter = some.getParameter();
          if (parameter==1){
              context.disableDefaultConstraintViolation();
              context.buildConstraintViolationWithTemplate("SomeObject.code.first").addConstraintViolation();
              return false;
          }
          if (parameter==2){
              context.disableDefaultConstraintViolation();
              context.buildConstraintViolationWithTemplate("SomeObject.code.second").addConstraintViolation();
              return false;
          }
          return true;
      }
  }
  </code></pre>
  
  <p>But context.buildConstraintViolationWithTemplate() adds an error message not a code. So spring ties to expand code like this:</p>
  
  <pre><code>ConstraintAnnotation.someObject
  </code></pre>
  
  <p>not</p>
  
  <pre><code>SomeObject.code.second
  </code></pre>
  
  <p>How add custome code instead of message?</p>