@DateTimeFormat with daylight saving time day with error

0

I'm having a problem converting date from 10/15/2017 (start of daylight savings time)

My mapping looks like this:

@Column(nullable = false)
@NotNull
@DateTimeFormat(pattern = "dd/MM/yyyy")
private Date dataVisita;

When processing the request, I get the following error:

  

Failed To Convert Property Value Of Type Java.Lang.String To Required   Type Java.Util.Date For Property DataVisita; Nested Exception Is   Org.Springframework.Core.Convert.ConversionFailedException: Failed To   Convert From Type Java.Lang.String To Type @ Javax.Persistence.Column   @ Javax.Validation.Constraints.NotNull   @ Org.Springframework.Format.Annotation.DateTimeFormat Java.Util.Date   For Value 10/15/2017; Nested Exception Is   Java.Lang.IllegalArgumentException: Can not Parse "10/15/2017": Illegal   Instant Due To Time Zone Offset Transition (America / Sao_Paulo)

I understand that the error informs me that the date 10/15/2017 00:00:00 does not exist. What I wanted the application to do was auto-transform for 10/15/2017 01:00:00

Is there any way to override the implementation of @DateTimeFormat to reimplement parse?

Thank you

    
asked by anonymous 17.10.2017 / 15:31

1 answer

-1

I've found an alternate solution that solves this problem:

link

@InitBinder
public void initBinder(WebDataBinder binder) {
    SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
    dateFormat.setLenient(false);

    // true passed to CustomDateEditor constructor means convert empty String to null
    binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, true));
}

Adding this to my controller, reseting the lenient and adding the CustomEditor.

    
17.10.2017 / 21:26