title: Validate input before Jackson in Spring Boot
body: <p>I've built a REST endpoint using Spring Boot. <code>JSON</code> is posted to the endpoint. Jackson converts the <code>JSON</code> giving me an object.</p>
  
  <p>The <code>JSON</code> look like this:</p>
  
  <pre><code>{
      "parameterDateUnadjusted": "2017-01-01",
      "parameterDateAdjusted": "2017-01-02"
  }
  </code></pre>
  
  <p>Jackson converts the <code>JSON</code> to an object based on this class:</p>
  
  <pre><code>public class ParameterDate {
  
      @NotNull(message = "Parameter Date Unadjusted can not be blank or null")
      @DateTimeFormat(pattern = "yyyy-MM-dd")
      private Date parameterDateUnadjusted;
      @NotNull(message = "Parameter Date Adjusted can not be blank or null")
      @DateTimeFormat(pattern = "yyyy-MM-dd")
      private Date parameterDateAdjusted;
      private Date parameterDateAdded;
      private Date parameterDateChanged;
  }
  </code></pre>
  
  <p>This all works fine. The issue I'm having is that I would like to validate the data before Jackson converts the data. For instance if I post </p>
  
  <pre><code>{
      "parameterDateUnadjusted": "2017-01-01",
      "parameterDateAdjusted": "2017-01-40"
  }
  </code></pre>
  
  <p>Where <code>parameterDateAdjusted</code> is not a valid date (there is no month with 40 days in it). Jackson converts this to <code>2017-02-09</code>. One way of getting around this is to have a class that is only strings let's call it <code>ParameterDateInput</code>. Validate each filed with Hibernate Validator in the <code>parameterDateInput</code> object and then copy the <code>parameterDateInput</code> object to <code>parameterDate</code> where each field has the correct type (dates are of type <code>Date</code> and not of type <code>String</code>). This to me doesn't look like a very elegant solution. Is there some other way I can solve this? How is data generally validated in Spring Boot when posted as <code>JSON</code>? I like to be able to send back a message to the user/client what is wrong with the data that is being posted.</p>