Failed to convert property value of type java.lang.String to required type java.util.Date


simply add @DateTimeFormat(pattern = "yyyy-MM-dd") with (-)


@DateTimeFormat(pattern = "yyyy-MM-dd")
private Date dateNaissance;

I'm getting this error when I try to input a date in a form.


@RequestMapping(value = "/docreatetask", method = RequestMethod.POST)
public String doCreateTask(Model model, @Valid Task task,
        BindingResult result, Principal principal,
        @RequestParam(value = "delete", required = false) String delete) {
    System.out.println(">TaskController doCreateTask " + task);

    if (result.hasErrors()) {
        System.out.println("/docreatetask in here");
        model.addAttribute("task", task);
        System.out.println("+++++"+task.getDeadline());// deadline is null  
        return "createtask";


<form:form method="POST"
<table class="formtable">
        <td class="label">Task</td>
        <td><form:input cssClass="control" path="taskname"
            name="taskname" type="text" /><br />
                <form:errors path="taskname" cssClass="error" /></td>
        <td class="label">Description</td>
        <td><form:textarea cssClass="control" path="description"
            name="description"></form:textarea><br />
                    <form:errors path="description" cssClass="error" /></td>
        <td class="label">Deadline (dd/mm/yyyy)</td>
        <td><form:input cssClass="control" path="deadline"
            name="deadline" type="date" /><br />
                <form:errors path="deadline" cssClass="error"></form:errors></td>

In the controller I wrote the following with the same error (and different formats like "yyyy/MM/dd")

public void initBinder(WebDataBinder webDataBinder) {
    SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
    webDataBinder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, true));

I also tried to add annotation in class (as well with different formats) but same error

    @Column(name = "deadline")
    @DateTimeFormat(pattern = "dd/MM/yyyy")
    private Date deadline;

@DateTimeFormat(pattern=“yyyy-MM-dd”) with Spring Mvc Rest Service gives “error 400 request syntactically incorrect”

In the spring forum they said that you need to have a conversion service initialized in your configuration in order to use the Formatter automátically. Something like:

<bean id="conversionService" class=""/>  

<bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">
    <property name="webBindingInitializer">
        <bean class="">
            <property name="conversionService" ref="conversionService" />

Add this in the controller. Change the dateFormat to your locale preference.

public void initBinder(WebDataBinder binder){
     binder.registerCustomEditor(       Date.class,     
                         new CustomDateEditor(new SimpleDateFormat("dd/MM/yyyy"), true, 10));   

Consider using this annotations in your model (Adapting format and TemporalType for your preferences)

@DateTimeFormat(pattern = "dd/MM/yyyy")

Finally I found the solution, maybe could be of use for others with the same issue. Just add this method to the controller:

public void initBinder(WebDataBinder binder) {
    SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
    binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, false));

right in the documentation:

But still don't understand why @DateTimeFormat(pattern="yyyy-MM-dd") doesn't work... With this solution there is no need of DateTimeFormat, so I annotated the param like the others:

@RequestParam(required = false) Date birthDay

LocalDate ld = new java.sql.Date( new java.util.Date().getTime() ).toLocalDate();