Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

question about handle date string in json.

 
zb cong
Ranch Hand
Posts: 416
  • Mark post as helpful
  • send pies
  • 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


 
E Armitage
Rancher
Posts: 989
9
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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
  • 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
  • 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
  • Quote
  • Report post to moderator
Thank you very much, it works by passing the long date value.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic