title: Best practice for using date parameters in Spring controllers?
body: <p>After written several backend APIs, I found that the following code duplicates in almost every method which needs to filter data by dates:</p>
  
  <pre class="lang-java prettyprint-override"><code>@GetMapping(value="/api/test")
  @ResponseBody
  public Result test(@RequestParam(value = "since", required = false) @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) LocalDate since,
                     @RequestParam(value = "until", required = false) @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) LocalDate until) {
      // Date validation code I want to eliminate
      since = ObjectUtils.defaultIfNull(since, DEFAULT_SINCE_DATE);
      until = ObjectUtils.defaultIfNull(until, LocalDate.now().plusDays(1));
      if(since.isAfter(until)) {
          throw new SinceDateAfterUntilDateException();
      }
  
      // Do stuff
  }
  </code></pre>
  
  <p>Obviously this is some kind of code smell. But, since I do need to validate <code>since</code> and <code>until</code> before using them to query the service/DAO, I am not sure where should I extract these code to?</p>
  
  <p>Any advice?</p>