title: Format Date in response of POST rest API
body: <p>I create a POST API in spring boot + kotlin. I create a LocalDate object but response is something not desired. I have used </p>
  
  <blockquote>
    <p>org.springframework.format.annotation.DateTimeFormat</p>
  </blockquote>
  
  <p>What I get is something like:</p>
  
  <pre><code>&lt;user&gt;
      &lt;email&gt;a@mail.com&lt;/email&gt;
      &lt;lname&gt;&lt;/lname&gt;
      &lt;fname&gt;&lt;/fname&gt;
      &lt;birthday&gt;
              &lt;year&gt;2000&lt;/year&gt;
              &lt;month&gt;JANUARY&lt;/month&gt;
              &lt;chronology&gt;
                  &lt;id&gt;ISO&lt;/id&gt;
                  &lt;calendarType&gt;iso8601&lt;/calendarType&gt;
              &lt;/chronology&gt;
              &lt;dayOfMonth&gt;1&lt;/dayOfMonth&gt;
              &lt;dayOfWeek&gt;SATURDAY&lt;/dayOfWeek&gt;
              &lt;era&gt;CE&lt;/era&gt;
              &lt;dayOfYear&gt;1&lt;/dayOfYear&gt;
              &lt;leapYear&gt;true&lt;/leapYear&gt;
              &lt;monthValue&gt;1&lt;/monthValue&gt;
      &lt;/birthday&gt;
  &lt;/user&gt;
  </code></pre>
  
  <p>What I want is something like (specifically <strong>birthDay</strong> tag):</p>
  
  <pre><code>&lt;user&gt;
      &lt;email&gt;a@mail.com&lt;/email&gt;
      &lt;lname&gt;&lt;/lname&gt;
      &lt;fname&gt;&lt;/fname&gt;
      &lt;birthday&gt;2000-01-01&lt;/birthday&gt;
  &lt;/user&gt;
  </code></pre>
  
  <p>Here is the code:</p>
  
  <p>dto class:</p>
  
  <pre><code>import org.springframework.format.annotation.DateTimeFormat
  import java.time.LocalDate
  
  @JacksonXmlRootElement
  data class User (var email: String? = "",
      var lname: String = "",
      var fname: String = "",
  
      @DateTimeFormat(pattern = "yyyy-MM-dd")
      var birthday: LocalDate? = null)
  </code></pre>
  
  <p>controller class:</p>
  
  <pre><code>@RestController
  @RequestMapping("/")
  class Controller {
  
  
      @PostMapping("/post")
      fun registerByMail(@Valid body: User) : ResponseEntity&lt;Any&gt; {
      .
      .
      .
      var user = User(birthDay = body.birthDay)
      return ResponseEntity.ok(user)
  </code></pre>
  
  <p>Please let me know where I doing wrong. I am making POST request using postman.</p>
  
  <p><strong>Edit</strong> : I have also tried solution mentioned here : <a href="https://stackoverflow.com/questions/29956175/json-java-8-localdatetime-format-in-spring-boot">JSON Java 8 LocalDateTime format in Spring Boot</a> but that also doesn't worked for me.</p>
  
  <p>When I use <strong>com.fasterxml.jackson.annotation.JsonFormat</strong> annotation and required dependency, I got following error:</p>
  
  <pre><code>&lt;defaultMessage&gt;Failed to convert value of type 'java.lang.String[]' to 
  required type 'java.time.LocalDate'; nested exception is 
  org.springframework.core.convert.ConversionFailedException: Failed to 
  convert from type [java.lang.String] to type 
  [@com.fasterxml.jackson.annotation.JsonFormat java.time.LocalDate] for value 
  '2000-01-01'; nested exception is java.lang.IllegalArgumentException: Parse 
  attempt failed for value [2000-01-01]&lt;/defaultMessage&gt;
  </code></pre>