title: Spring deserializes a LocalDate in a @RequestBody differently from one in a @RequestParam - why, and can they be the same?
body: <p>QUESTION: Spring appears to use different deserialization methods for <code>LocalDate</code> depending on whether it appears in a <code>@RequestBody</code> or a request <code>@ReqestParam</code> - is this correct, and if so, is there a way to configure them to be the same throughout an application?</p>
  
  <p>BACKGROUND: In my <code>@RestController</code>, I have two methods - one GET, and one POST. The GET expects a request parameter ("date") that is of type <code>LocalDate</code>; the POST expects a JSON object in which one key ("date") is of type <code>LocalDate</code>. Their signatures are similar to the following:</p>
  
  <pre><code>@RequestMapping(value = "/entity", method = RequestMethod.GET)
  public EntityResponse get(
         Principal principal,
         @RequestParam(name = "date", required = false) LocalDate date) 
  
  @RequestMapping(value = "/entity", method = RequestMethod.POST)
  public EntityResponse post(
         Principal principal,
         @RequestBody EntityPost entityPost)
  
  public class EntityPost {
         public LocalDate date;
  }
  </code></pre>
  
  <p>I've configured my ObjectMapper as follows:</p>
  
  <pre><code>@Bean
  public ObjectMapper objectMapper() {
  
     ObjectMapper objectMapper = new ObjectMapper();
     objectMapper.enable(SerializationFeature.INDENT_OUTPUT);
     objectMapper.registerModule(new JavaTimeModule());
     objectMapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
  
     return objectMapper;
  }
  </code></pre>
  
  <p>Which ensures the system accepts <code>LocalDate</code> in the format yyyy-MM-dd and deserializes it as expected - at least when it is part of a <code>@RequestBody</code>. Thus if the following is the request body for the POST</p>
  
  <pre><code>{
  "date": 2017-01-01
  }
  </code></pre>
  
  <p>The system deserializes the request body into an <code>EntityPost</code> as expected. </p>
  
  <p>However, that configuration does not apply to the deserialization of the <code>@RequestParam</code>. As a result, this fails:</p>
  
  <pre><code>// fail!
  /entity?date=2017-01-01
  </code></pre>
  
  <p>Instead, the system appears to expect the format MM/dd/yy. As a result, this succeeds:</p>
  
  <pre><code>// success!
  /entity?date=01/01/17
  </code></pre>
  
  <p>I know I can change this on a parameter-by-parameter basis using the @DateTimeFormat annotation. I know that if I change the signature of the GET method as follows, it will accept the first format:</p>
  
  <pre><code>@RequestMapping(value = "/entity", method = RequestMethod.GET)
  public EntityResponse get(
         Principal principal,
         @RequestParam(name = "date", required = false) @DateTimeFormat(iso=DateTimeFormat.ISO.DATE) LocalDate date) 
  </code></pre>
  
  <p>However, I would prefer if I didn't have to include an annotation for every usage of <code>LocalDate</code>. Is there any way to set this globally, so that the system deserializes every <code>@RequestParam</code> of type <code>LocalDate</code> in the same way? </p>
  
  <p>For reference:</p>
  
  <p>I'm using Spring <strong>4.3.2.RELEASE</strong></p>
  
  <p>I'm using Jackson <strong>2.6.5</strong></p>