问题
ObjectObject oo= new ObjectObject();
oo.put("name", FBSUtility.wrap("Wiley E."));
oo.put("DoB", new Date()); // <-- no can do
How can I put a Java Date in an ObjectObject? There is no .wrap method for a Date value. It must be possible somehow, for I can get one out using
Date d= oo.get("DoB").dateValue();
but how to put one in?? Thanks!!
UPDATE
This is what I used a long time:
JSContext jsContext = JavaScriptUtil.getJSContext();
ObjectObject oo = new ObjectObject();
oo.put("due", FBSUtility.wrap(jsContext, due.getTime());
and that works, but... it results in a Cannot serialize JavaScript function error when the object is to be serialized.
回答1:
The solution is to ditch JSContext, ObjectObject and ArrayObject objects altogether, and use one of the other JSON classes available. I started using these two:
import com.ibm.commons.util.io.json.JsonJavaArray;
import com.ibm.commons.util.io.json.JsonJavaObject;
An additional advantage is that one can forget all about the FBSUtility wrap thing.
来源:https://stackoverflow.com/questions/57475816/xpages-how-to-put-a-java-date-value-in-an-objectobject