Validate a date field in javascript to send to server api

Asked

Viewed 46 times

0

You guys, good morning.

I am with a very boring error, I am trying to put a form in Vue.js, however, when I send the information to the server and in java, is breaking a date exception;

[2m[nio-8080-exec-2][0;39m [36m.w.s.m.s.DefaultHandlerExceptionResolver[0;39m [2m:[0;39m Resolved [org.springframework.http.converter.HttpMessageNotReadableException: Invalid JSON input: Cannot deserialize value of type `java.util.Date` from String "27-02-2014": not a valid representation (error: Failed to parse Date value '27-02-2014': Cannot parse date "27-02-2014": not compatible with any of standard forms ("yyyy-MM-dd'T'HH:mm:ss.SSSZ", "yyyy-MM-dd'T'HH:mm:ss.SSS", "EEE, dd MMM yyyy HH:mm:ss zzz", "yyyy-MM-dd")); 
nested exception is com.fasterxml.jackson.databind.exc.InvalidFormatException: Cannot deserialize value of type `java.util.Date` from String "27-02-2014": not a valid representation 
(error: Failed to parse Date value '27-02-2014': 
Cannot parse date "27-02-2014": not compatible with any of standard forms 
("yyyy-MM-dd'T'HH:mm:ss.SSSZ", "yyyy-MM-dd'T'HH:mm:ss.SSS", "EEE, dd MMM yyyy HH:mm:ss zzz", "yyyy-MM-dd"))
 
at [Source: (PushbackInputStream); line: 1, column: 22] (through reference chain: ServidorRecadastramentoRequest["dataExpedicaoCTPS"]).

I tried to format the fields on the screen in the following ways:

formatDate(value) {
  if (value) {
    return moment(String(value)).format('DD/MM/YYYY')
  }
},

formatDate1(value) {
  if (value){
    return moment("2014-02-27T10:00:00").format('DD-MM-YYYY')
  }
},

1 answer

1

In the error message is the answer:

Cannot parse date "27-02-2014": not compatible with any of standard forms 
("yyyy-MM-dd'T'HH:mm:ss.SSSZ", "yyyy-MM-dd'T'HH:mm:ss.SSS", "EEE, dd MMM yyyy HH:mm:ss zzz", "yyyy-MM-dd"))

Your code is sending the date in format DD-MM-YYYY but the server waits for the American format: yyyy-MM-dd.

  • Yes, I had already noticed the error, I tried to fix inside the server in the java class, and also in the page service, I’m missing something

  • Log the javascript to see if the formatting is being done as expected by you.

Browser other questions tagged

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