File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Spring and the fly likes question about handle date string in json. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Frameworks » Spring
Bookmark "question about handle date string in json." Watch "question about handle date string in json." New topic
Author

question about handle date string in json.

zb cong
Ranch Hand

Joined: Jan 14, 2002
Posts: 416
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

Joined: Mar 17, 2012
Posts: 892
    
    9
JSON doesn't have a date type. What type is the field what holds depositDate in the PaymentSearchFilter class?
zb cong
Ranch Hand

Joined: Jan 14, 2002
Posts: 416
yes, it is a java.util.Date type.

Thanks.
E Armitage
Rancher

Joined: Mar 17, 2012
Posts: 892
    
    9
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

Joined: Jan 14, 2002
Posts: 416
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

Joined: Mar 17, 2012
Posts: 892
    
    9
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

Joined: Jan 14, 2002
Posts: 416
Thank you very much, it works by passing the long date value.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: question about handle date string in json.
 
Similar Threads
getAsText() not called Spring MVC PropertyEditorSupport AJAX
getting focused jtextfield in exteds jPanel
Retrieve records from MySQL using radio button
@SessionAttributes with a Validator set up using @InitBinder
IllegalArgumentException: Cannot convert value of type [java.lang.String] to required