• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

question about handle date string in json.

 
Ranch Hand
Posts: 416
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,

take look following ajax call and spring controller code, note, the "depositDate" field is date type, when the call is executed, the server side return the "Bad Request" errors. But if i set this field as null, it works, so i conclude i may not handle the date type well. who can helps? thanks.




the controller


 
Rancher
Posts: 989
9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
JSON doesn't have a date type. What type is the field what holds depositDate in the PaymentSearchFilter class?
 
zb cong
Ranch Hand
Posts: 416
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
yes, it is a java.util.Date type.

Thanks.
 
E Armitage
Rancher
Posts: 989
9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So whatever mechanism you are using to convert depositDate to util date is probably where the issue is. e.g if you change that property to String does the submit work?
P.S If you have control of both server and client side then it's better to pass timestamps for dates and times because they are more portable as the client and server don't need to know about each other's date presentation format.
 
zb cong
Ranch Hand
Posts: 416
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think the string should works, because other fields are string, they work well. otherwise, i could not change the type to timestamps, the Date type is mandatory,thanks.
 
E Armitage
Rancher
Posts: 989
9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
By passing timestamps I mean passing the long value of the timestamp. To correctly pass the data as a string all the time you have to use the same format on the client that you are using on the server.
 
zb cong
Ranch Hand
Posts: 416
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you very much, it works by passing the long date value.
 
reply
    Bookmark Topic Watch Topic
  • New Topic