title: Custom message for ConstraintValidator
body: <p>I am using ConstraintValidator implementation as given below for validating request object for a spring boot REST service</p>
  
  <pre><code>@Target({ FIELD, METHOD, PARAMETER, ANNOTATION_TYPE })
  @Retention(RUNTIME)
  @Constraint(validatedBy = MyRequestValidator.class)
  @Documented
  public @interface MyRequestValidation {
  
      String message() default "Mandatory fields missing";
  
      Class&lt;?&gt;[] groups() default {};
  
      Class&lt;? extends Payload&gt;[] payload() default {};
  }
  
  public class MyRequestValidator
              implements
                  ConstraintValidator&lt;MyRequestValidation, MyRequest&gt;{
     @Override
      public void initialize(MyRequestValidation constraintAnnotation) {
          // Nothing to do here
      }
     @Override
      public boolean isValid(MyRequest myRequest, ConstraintValidatorContext context) {
   //do some validation
       context.disableDefaultConstraintViolation();    
       context.buildConstraintViolationWithTemplate("Id can contain only alphabets and digits")
      .addPropertyNode("id")
      .addConstraintViolation();
     }
  }
  
  //REST end point
  public interface RestApi{
    @Produces(MediaType.XML)
    @Consumes(MediaType.XML)
    @POST
    MyResponse action(@MyRequestValidation MyRequest myRequest);
  }
  
  @Component
  public class RestApiImpl implements RestApi {
  ..
  }
  </code></pre>
  
  <p>This produces output as</p>
  
  <pre><code>[PARAMETER]
  [myRequest.arg0.id]
  [Id can contain only alphabets and digits]
  </code></pre>
  
  <p>Is there anyway to produce JSON or XML message (or based on the @Produces annotation on the REST end point). I am using Hibernate implementations of these interface ConstraintValidatorContext</p>