@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<Long, Person> find = new Model.Finder<Long, Person>(Person.class); }
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())); }
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"])
public class Global extends GlobalSettings {
public void onStart(Application app) {
ObjectMapper mapper = new ObjectMapper();
mapper.registerModule(new Jdk8Module());
mapper.registerModule(new JSR310Module());
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
Json.setObjectMapper(mapper);
}
}
Hey guys,I'm having problem trying to use java.time.LocalDate on my model
@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<Long, Person> find = new Model.Finder<Long, Person>(Person.class); } Controller:
public class PersonController extends Controller { public Result create() { Person person = Json.fromJson(request().body().asJson(), Person.class); person.save(); return ok(
...