[Json-rpc-java] handling Date
Michael Clark
michael at metaparadigm.com
Wed Sep 26 21:34:56 SGT 2007
Hi Boris,
Yes you are right. Date support is pretty limited. Your best workaround
for the moment is to do something like the following to make sure you
send a number.
JSONObject["time"] ? JSONObject["time"] : 0
You could also write a custom serializer to handle your string format.
Unfortunately as the de-serialization on the JS side doesn't support
constructors for the Date class (it can't be represented in simple
JSON), you will receive a number in milliseconds (or a String if you
wrote a custom serializer).
To unmarshall the date on the JS side you need to do:
var date = new Date(result.time);
Michael.
Goykhman, Boris wrote:
> Hi
>
>
>
> I have a question about converting a javascript form textbox value to
> java.util.Date class on the server side.
>
> So far I discovered that passing milliseconds is the best option, like
> in the code below:
>
>
>
> formObj : {
>
> .....
>
> dateParam : {
>
> javaClass : "java.util.Date",
>
> time : 1234567890
>
> }
>
> .....
>
> }
>
>
>
> However, if passing milliseconds is not an option, is there any way to
> pass a date format, like "MM/dd/yyyy", and still obtain a valid date
> object?
>
> And even if I do write a date parser and then extract milliseconds, a
> problem arises when I submit an empty textbox:
>
>
>
> JSONObject["time"] is not a number.]
>
>
>
> , because I make sure that time is null in order to get a null Date on
> the server side (for validation purposes). Null Date scenario is normal
> and should not be a showstopper.
>
>
>
> Is there a better alternative than passing time in milliseconds?
>
>
>
> Thanks
>
>
>
>
>
>
>
>
>
>
>
>
>
> *The information contained in this e-mail and any attachments may be confidential and/or proprietary. If you are not an intended recipient or an authorized agent of an intended recipient, you are hereby notified that any dissemination, distribution or copying of this e-mail is strictly prohibited. If you have received this e-mail in error, please notify the sender by replying to this message and permanently delete the e-mail and any attachments immediately.
> _______________________________________________
> Json-rpc-java mailing list
> Json-rpc-java at oss.metaparadigm.com
> http://oss.metaparadigm.com/mailman/listinfo/json-rpc-java
>
More information about the Json-rpc-java
mailing list