0 Replies Latest reply on Apr 4, 2014 5:13 AM by Rudy De Busscher

    Customize message from Bean Validation with JAX-RS response

    Rudy De Busscher Newbie

      Hi All,


      (Using Wildfly)


      I have some JAX-RS methods that take JSON objects as parameter.


      On These parameters, I have placed some validation constraints, like @Size, with a custom message.  This custom message is used but a lot of more information is available in the response of the REST call which.


      The JAXRS controller





          public RegistrationResult newRegistration(@Valid RegistrationDTO registrationDTO) {




      The DTO class

      public class RegistrationDTO {



          @Size(min = 1, max=30, message = "First name (firstName) length must be between 1 and 30 characters long.")

          private String firstName;




          @Size(min = 1, max=50, message = "Last name (lastName) length must be between 1 and 50 characters long.")

          private String lastName;





      And the response



      [Last name (lastName) length must be between 1 and 50 characters long.]




      The only way that I have found to answer with a proper JSON object (now it is text), is to write a WriterInterceptor and parse the response from RestEasy. Because I need to return a JSON object as answer (RegistrationResult) where there is some place to put error messages.


      Anyone an idea how I can intercept the generation of the current String response?


      Thx a lot

      Rudy De Busscher