title: How to use java.time.LocalDate on a Play Framework JSON Rest?
body: <p>I'm trying, without success, to make Play serialize and deserialize java 8 LocalDate.</p>
  
  <p>On Play 2.4, it's said to work out of the box:</p>
  
  <blockquote>
    <p>Play 2.4 now requires JDK 8. Due to this, Play can, out of the box, provide support for Java 8 data types. For example, Play’s JSON APIs now support Java 8 temporal types including Instance, LocalDateTime and LocalDate.</p>
  </blockquote>
  
  <p>But I'm unable to make it work.</p>
  
  <p>Here is what I have:
  I'm using Play 2.4.3, with PlayJava and PlayEbean plugins</p>
  
  <p>Model</p>
  
  <pre><code>@Entity
  public class Person extends Model {
  
      @Id
      public Long id;
  
      public String name;
  
      public LocalDate dayOfBirth;
  
      @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "dd/MM/yyyy")
      public LocalDate anotherDate;
  
      @Formats.DateTime(pattern = "dd/MM/yyyy")
      public LocalDate andAnotherOne;
  
      public static Model.Finder&lt;Long, Person&gt; find = new Model.Finder&lt;Long, Person&gt;(Person.class);
  }
  </code></pre>
  
  <p>Controller</p>
  
  <pre><code>public class PersonController extends Controller {
  
      public Result create() {
          Person person = Json.fromJson(request().body().asJson(), Person.class);
  
          person.save();
  
          return ok(Json.toJson(person));
      }
  
      public Result all() {
          return ok(Json.toJson(Person.find.all()));
      }
  }
  </code></pre>
  
  <p>routes</p>
  
  <pre><code>POST        /person              @controllers.PersonController.create()
  
  GET         /person              @controllers.PersonController.all()
  </code></pre>
  
  <p>I test it with a chrome app for REST and got error in the three forms:</p>
  
  <pre><code>{"name":"Fred","dayOfBirth":"2015-09-30"}
  {"name":"Fred","anotherDate":"30/09/2015"}  
  {"name":"Fred","andAnotherOne":"30/09/2015"}
  </code></pre>
  
  <p>Error</p>
  
  <pre><code>java.lang.RuntimeException:     com.fasterxml.jackson.databind.JsonMappingException: Can not instantiate     value of type [simple type, class java.time.LocalDate] from String value     ('2015-09-30'); no single-String constructor/factory method
   at [Source: N/A; line: -1, column: -1] (through reference chain:     models.Person["dayOfBirth"])
  </code></pre>
  
  <p>What am I missing?</p>
  
  <p><strong>update:</strong> sample app: <a href="https://github.com/fredferrao/LocalDateJSONTest" rel="nofollow">https://github.com/fredferrao/LocalDateJSONTest</a></p>