XPage:如何将 Java 日期值放入 ObjectObject [英] XPages: how to put a Java Date value in an ObjectObject

查看:29
本文介绍了XPage:如何将 Java 日期值放入 ObjectObject的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

ObjectObject oo= new ObjectObject();
oo.put("name", FBSUtility.wrap("Wiley E."));
oo.put("DoB", new Date());  // <-- no can do

如何将 Java 日期放入 ObjectObject 中?Date 值没有 .wrap 方法.一定有可能,因为我可以使用

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!!

更新

这是我用了很久的:

JSContext jsContext = JavaScriptUtil.getJSContext();
ObjectObject oo = new ObjectObject();
oo.put("due", FBSUtility.wrap(jsContext, due.getTime());

这可行,但是...当对象要被序列化时,它会导致无法序列化 JavaScript 函数错误.

and that works, but... it results in a Cannot serialize JavaScript function error when the object is to be serialized.

推荐答案

解决方案是完全抛弃 JSContext、ObjectObject 和 ArrayObject 对象,并使用其他可用的 JSON 类之一.我开始使用这两个:

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;

另一个优点是可以忘记 FBSUtility 包装的所有内容.

An additional advantage is that one can forget all about the FBSUtility wrap thing.

这篇关于XPage:如何将 Java 日期值放入 ObjectObject的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆