XPages: how to put a Java Date value in an ObjectObject

拥有回忆 提交于 2021-01-29 18:08:20

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!