title: Conversion data type in spring mvc
body: <p>I have an problem in my Spring MVC.</p>
  
  <pre><code>@RequestMapping(value = "/novo", method = RequestMethod.GET)
  public ModelAndView novoTimeSheet() {
      return new ModelAndView("timesheetcrud/novo", "timesheet", new TimeSheet());
  }
  </code></pre>
  
  <p>My <code>TimeSheet</code> class has:</p>
  
  <pre><code>@NotNull(message = "timesheet.cadastro.horainicio.obrigatorio")
  @Temporal(TemporalType.TIME)
  @Column(name = "INICIO", nullable = false)
  private Date horaInicio;
  
  @NotNull(message = "timesheet.cadastro.horafim.obrigatorio")
  @Temporal(TemporalType.TIME)
  @Column(name = "FIM", nullable = false)
  private Date horaFim;
  </code></pre>
  
  <p>My <code>addTimeSheet</code>:</p>
  
  <pre><code>@RequestMapping(value = "/addtimesheet", method = RequestMethod.POST)
  public String addTimeSheet(@ModelAttribute("timesheet")TimeSheet timeSheet,
                           ModelMap model) {
  </code></pre>
  
  <p>In browser when I put something not equal date, I have this error:</p>
  
  <pre><code>org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.springframework.validation.BindException: org.springframework.validation.BeanPropertyBindingResult: 2 errors
  Field error in object 'timesheet' on field 'horaFim': rejected value [lala]; 
  codes [typeMismatch.timesheet.horaFim,typeMismatch.horaFim,typeMismatch.java.util.Date,typeMismatch]; 
  arguments [
    org.springframework.context.support.DefaultMessageSourceResolvable: codes [timesheet.horaFim,horaFim]; 
    arguments []; 
    default message [horaFim]
  ]; 
  default message [
    Failed to convert property value of type 'java.lang.String' to required type 'java.util.Date' for property 'horaFim'; 
    nested exception is org.springframework.core.convert.ConversionFailedException: Failed to convert from type java.lang.String to type @javax.validation.constraints.NotNull @javax.persistence.Temporal @javax.persistence.Column java.util.Date for value 'lala'; 
    nested exception is java.lang.IllegalArgumentException
  ]
  Field error in object 'timesheet' on field 'horaInicio': rejected value [teste]; 
  codes [typeMismatch.timesheet.horaInicio,typeMismatch.horaInicio,typeMismatch.java.util.Date,typeMismatch]; 
  arguments [
    org.springframework.context.support.DefaultMessageSourceResolvable: codes [timesheet.horaInicio,horaInicio]; 
    arguments []; 
    default message [horaInicio]
  ]; 
  default message [
    Failed to convert property value of type 'java.lang.String' to required type 'java.util.Date' for property 'horaInicio'; 
    nested exception is org.springframework.core.convert.ConversionFailedException: Failed to convert from type java.lang.String to type @javax.validation.constraints.NotNull @javax.persistence.Temporal @javax.persistence.Column java.util.Date for value 'teste'; 
    nested exception is java.lang.IllegalArgumentException
  ]
  </code></pre>
  
  <p><strong>How can I do it? Expect <code>Date</code> but I put <code>String</code> in the field, I'd like to validate before my controller.</strong></p>