Package org.zkoss.json
Class JSONs
- java.lang.Object
-
- org.zkoss.json.JSONs
-
public class JSONs extends java.lang.ObjectUtilities to JSON-ize objects that JSON is not aware, such as Date.Notice that implementing
JSONAwareis another way to make an object able to JSON-ized.- Since:
- 5.0.5
- Author:
- tomyeh
-
-
Constructor Summary
Constructors Constructor Description JSONs()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static java.lang.Stringd2j(java.util.Date d)Marshalls a Date object to a string, such that it can be add toJSONArrayorJSONObject(a.k.a., JSON-ize).static java.util.Datej2d(java.lang.String s)Unmarshalls a string to a date.
-
-
-
Method Detail
-
d2j
public static final java.lang.String d2j(java.util.Date d)
Marshalls a Date object to a string, such that it can be add toJSONArrayorJSONObject(a.k.a., JSON-ize).It is used with
j2d(java.lang.String).d2j(java.util.Date)is used to JSON-ize a Date object, whilej2d(java.lang.String)is to unmarshall it back to a Date object.Notice it assumes
TimeZones.getCurrent()(and Locale-independent). However, the result string has no time zone information. Thus, if the client is in different time zone, the date object will be different. However, since the object will be marshalled back in the same way, the value sent back from the client will be the same (regardless the time zone is different).
-
j2d
public static final java.util.Date j2d(java.lang.String s) throws java.text.ParseExceptionUnmarshalls a string to a date. It is used withd2j(java.util.Date).d2j(java.util.Date)is used to JSON-ize a Date object, whilej2d(java.lang.String)is to unmarshall it back to a Date object.Notice it assumes
TimeZones.getCurrent()(and Locale-independent).- Throws:
java.text.ParseException
-
-