问题描述
在文本末尾查看更新
我有一个脚本化数据源.数据集基于包含多个集合的Java对象.
I have a scripted data source. The datasets are based on a Java object which contains a number of collections.
我的报告包含页眉,正文和页脚,所有这些条目都具有绑定到此数据集的项目.顶级数据集存储对Java对象的引用.这被传递到子数据集,该子数据集返回各种列表.
My report contains a header, body and footer all of which have items bound to this data set. The top-level dataset stores a reference to the Java object. This is passed to sub-datasets which return various lists.
POJO
public class Protocol {
String name;
int id;
List<Device> devices;
List<TestResult> results;
...
}
DAO
public class DAO {
public List<Protocol> getProtocols(String filePath) {
return deserialise(filePath);
}
}
协议数据集
open:
model = new Packages.com.acme.atf.model.dao.AtfObjects();
path = inputParams["ProtocolPath"];
iterP = model.getProtocols(path).iterator();
countP = 0;
fetch:
if(iterP.hasNext()) {
var p = iterP.next();
row["ProductId"] = p.getId();
row["ProductVersion"] = p.getProductVersion();
row["ProtocolObject"] = p;
log("po=" + p);
return true;
}
return false;
设备数据集
open:
protocol = inputParams["ProtocolObject"];
if(protocol == null) {
log("Protocol is NULL");
return;
}
iterD = protocol.getDevices().iterator();
日志输出记录:
po=com.acme.atf.model.Protocol@5a5901
Protocol is NULL
表示对象添加到结果中时不为null,但传递给第二个数据集时为null.
which indicates that the object is not null when added to the result but null when passed to the second dataset.
我还尝试了将Protocol数据集提取到报表中,从而创建了一个表. ProtocolObject的值已为空. (请注意,其他属性填充有合理的值)
I also tried pulling the Protocol dataset into the report, thereby creating a table. The value of ProtocolObject is already null. (Just to be clear, the other attributes are filled with sensible values)
什么可能导致row['ProtocolObject']
变为空?
更新我基于包含上述脚本的库创建了一个简单的报告.我将协议数据集作为表格插入,具有ProtocolObject
的单元格为不为空!我拉入第二张表,并且两个带有ProtocolObject
的单元格都为空.在日志中,我可以看到完成了2次抓取,并且每次抓取都有一个不同的Protocol实例:
UPDATEI created a simple report based on a library containing the above scripts. I pulled in the Protocol dataset as a table and the cell with ProtocolObject
is not null! I pulled in a second table and both cells with ProtocolObject
are null. In the logs I can see that 2 fetches are done and each gets a different Protocol instance:
Wed Jul 23 2014 07:28:37 GMT+0200 (CEST) ===========================================
Wed Jul 23 2014 07:28:37 GMT+0200 (CEST) Open protocol: testcase.protocol
Wed Jul 23 2014 07:28:37 GMT+0200 (CEST) exit open P
Wed Jul 23 2014 07:28:37 GMT+0200 (CEST) po=com.acme.atf.model.Protocol@2892c0
Wed Jul 23 2014 07:28:37 GMT+0200 (CEST) Protocol: no more records
Wed Jul 23 2014 07:28:37 GMT+0200 (CEST) ===========================================
Wed Jul 23 2014 07:28:37 GMT+0200 (CEST) Open protocol: testcase.protocol
Wed Jul 23 2014 07:28:37 GMT+0200 (CEST) exit open P
Wed Jul 23 2014 07:28:37 GMT+0200 (CEST) po=com.acme.atf.model.Protocol@13ea352
Wed Jul 23 2014 07:28:37 GMT+0200 (CEST) Protocol: no more records
推荐答案
我想我已经找到了原因.
I think I have found the reason.
对于某些人来说可能是显而易见的,但是原因似乎是Protocol
对象不是完全可序列化的.我发现其中一个包含的类未实现java.io.Serializable
.
It might be obvious to some, but the cause seems to be that the Protocol
object was not fully serialisable. I found that one of the contained classes did not implement java.io.Serializable
.
它可能在文档中的某个地方,但是,如果要在结果集中包含Java对象,则它必须是完全可序列化的.
It's probably in the docs somewhere but, if you want to include a Java Object in your result set, it must be completely serialisable.
这篇关于是什么可能导致BIRT在获取和渲染之间丢失对象引用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!