【发布时间】:2013-03-12 13:39:35
【问题描述】:
我正在尝试使用flexjson 库。但在我的对象中,我必须使用:
com.google.api.client.util.DateTime 没有没有参数的构造函数。我总是收到NoSuchMethodException 和消息:Flexjson will instantiate any protected, private, or public no-arg constructor. 我有资源并试图用它做点什么,这里是代码:
constructor = clazz.getDeclaredConstructor();
constructor.setAccessible(true);
return constructor.newInstance();
由于缺少空构造函数,clazz.getDeclaredConstructor() 中抛出异常。假设这些签名,找到构造函数的最佳方法是什么:
DateTime(long timestamp)?
有人在这个库中遇到过这种问题吗?也许你可以建议使用其他的。我正在使用它来序列化Google Cloud Endpoints 生成的对象。也许我可以用不同的方法做到这一点?
【问题讨论】:
-
最好的方法是有一个空的构造函数。如果它存在于 json 对象中,您的时间戳将在稍后设置。为此,您可以考虑延长 DateTime。
-
njzk2,我无法扩展
DateTime,因为它在自动生成的文件中,并且它是从app-engine后端上的java.util.Date对象生成的。
标签: java android google-app-engine google-cloud-endpoints flexjson