title: Spring - Failed to convert property value of type java.lang.String to required type java.util.Date
body: <p>I have read some topics about this, but none of them helped me.</p>
  
  <p>My problem is that the conversion is working well, but today I received a user's complaint using ios 12 and Safari. Immediately I tested on Iphone with ios 12 and I couldn't reproduce the error. 
  Could it be some device specific configuration or regional settings?</p>
  
  <p>Please help!
  Thanks.</p>
  
  <p><strong>Controller</strong></p>
  
  <pre><code>@Controller
  public class SaleController {
  
      @InitBinder
      public void setPropertyBinder(WebDataBinder dataBinder) {
  
          //The date format to parse or output your dates
          SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
          dateFormat.setLenient(false);
  
          //Create a new CustomDateEditor
          CustomDateEditor editor = new CustomDateEditor(dateFormat, true);
  
          //Register it as custom editor for the Date type
          dataBinder.registerCustomEditor(Date.class, editor);            
      }
  
      @RequestMapping(value="/venda3", method=RequestMethod.POST)
      public String venda3(@Valid @ModelAttribute("anuncioImovel") AnuncioImovel anuncioImovel, BindingResult resultImovel, Model model, Principal principal, HttpServletRequest request) {
  
      }    
  }
  </code></pre>
  
  <p><strong>Model</strong></p>
  
  <pre><code>@Entity
  public class AnuncioImovel {
  
      @Column(nullable=true)
      @Temporal(TemporalType.DATE)
      @DateTimeFormat(pattern="yyyy-MM-dd")
      @Past
      private Date inicioLocacao;
  
      @Column(nullable=true)
      @Temporal(TemporalType.DATE)
      @DateTimeFormat(pattern="yyyy-MM-dd")
      @Future 
      private Date terminoLocacao;
  
      public void setInicioLocacao(Date inicioLocacao) {      
          this.inicioLocacao = inicioLocacao;
      }
  
      public void setTerminoLocacao(Date terminoLocacao) {
          this.terminoLocacao = terminoLocacao;
      }
  }
  </code></pre>
  
  <p><strong>Thymeleaf Template</strong></p>
  
  <pre><code>&lt;!-- Início Locação --&gt;
  &lt;div class="form-group"&gt;
      &lt;label for="frmInicioLocacao" class="form-control-label text-primary"&gt;&lt;strong&gt;Início Locação&lt;/strong&gt;&lt;/label&gt;
      &lt;input type="date" class="form-control" id="frmInicioLocacao" name="inicioLocacao"  
             th:value="${anuncioImovel.inicioLocacao} ? ${#dates.format(anuncioImovel.inicioLocacao, 'yyyy-MM-dd')}"
             th:classappend="${#fields.hasErrors('anuncioImovel.inicioLocacao')} ? 'is-invalid' : ''"
             oninput="javascript: this.value = this.value.slice(0, 10);"/&gt;
  
      &lt;div class="invalid-feedback"&gt;
          &lt;span th:errors="*{anuncioImovel.inicioLocacao}"&gt;&lt;/span&gt;
      &lt;/div&gt;
  &lt;/div&gt;
  
  &lt;!-- Término Locação --&gt;
  &lt;div class="form-group"&gt;
      &lt;label for="frmTerminoLocacao" class="form-control-label text-primary"&gt;&lt;strong&gt;Término Locação&lt;/strong&gt;&lt;/label&gt;
      &lt;input type="date" class="form-control" id="frmTerminoLocacao" name="terminoLocacao" 
             th:value="${anuncioImovel.terminoLocacao} ? ${#dates.format(anuncioImovel.terminoLocacao, 'yyyy-MM-dd')}"
             th:classappend="${#fields.hasErrors('anuncioImovel.terminoLocacao')} ? 'is-invalid' : ''"
             oninput="javascript: this.value = this.value.slice(0, 10);"/&gt;
  
      &lt;div class="invalid-feedback"&gt;
          &lt;span th:errors="*{anuncioImovel.terminoLocacao}"&gt;&lt;/span&gt;
      &lt;/div&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p><strong>Print error sent by the user</strong>
  <a href="https://i.stack.imgur.com/Cgikd.png" rel="nofollow noreferrer">click here</a></p>
  
  <p><strong>My test</strong>
  In my test on Iphone the dates are shown this way, and the conversion works (I don't know how the date is shown on user's device):
  <a href="https://i.stack.imgur.com/XzjWM.jpg" rel="nofollow noreferrer">Click here</a></p>