@Datetimeformat with daylight saving time error

Asked

Viewed 346 times

0

I’m having a problem converting date of day 15/10/2017 (start of daylight saving time)

My mapping is like this:

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

While 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 Datavisit; 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 15/10/2017; Nested Exception Is Java.lang.Illegalargumentexception: Cannot Parse "15/10/2017": Illegal Instant Due To Time Zone Offset Transition (America/Sao_paulo)

I understand that the error informs me that the date 15/10/2017 00:00:00 does not exist. What I wanted the application to perform was the automatic transformation to 15/10/2017 01:00:00

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

Thank you

1 answer

-1

I’ve found an Alternate Solution that solves this problem:

https://jira.spring.io/browse/SPR-8669

@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.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.