Java Castor映射数组
我有一个具有构造函数的类:Java Castor映射数组,java,xml,marshalling,castor,Java,Xml,Marshalling,Castor,我有一个具有构造函数的类: public ContEmpirical(double xs[], double fs[]) { Check.check(xs.length == fs.length + 1 && fs.length > 0, "Empirical distribution array mismatch"); this.xs = new double[xs.length]; this.xs = xs; th
public ContEmpirical(double xs[], double fs[]) {
Check.check(xs.length == fs.length + 1 && fs.length > 0,
"Empirical distribution array mismatch");
this.xs = new double[xs.length];
this.xs = xs;
this.cs = new double[xs.length];
double fTotal = 0.0;
for (int i = 0; i < fs.length; i++)
fTotal += fs[i];
cs[0] = 0;
for (int i = 0; i < fs.length; i++)
cs[i + 1] = cs[i] + fs[i] / fTotal;
}
我拥有的映射文件是:
<class name="tools.ContEmpirical">
<description xmlns="">
Mapping for class tools.ContEmpirical
</description>
<map-to xml="ContEmpirical"/>
<field name="xs" type="double" collection="array" set-method="%1" get-method="getXs" required="true">
<bind-xml node="attribute"/>
</field>
<field name="fs" type="double" collection="array" set-method="%2" get-method="getFs" required="true">
<bind-xml node="attribute"/>
</field></class>
类工具的映射。上下文
然而,当我尝试整理Contemperical的一个实例时,我得到了以下XML:
<ContEmpirical xs="0.2 0.3 0.4 0.8"/>
当我真的应该得到这样的东西时:
<ContEmpirical xs="0.2 0.3 0.4 0.8" fs="0.2 0.3 0.4 0.8"/>
映射中有什么我遗漏的吗?你能发布上下文类吗?您是否将fs数组初始化为字段级别的内容 更新:我一定错过了什么。您说过在输出xml中“期望”fs。但是这个类是否有一个名为fs的属性?从您发布的构造函数代码来看,fs从未在内部赋值(不过有一个名为fs的参数用于计算cs)
所以实际上,您的对象只有一个xs和cs变量,并且在xml中,如果您为cs声明映射,您应该得到cs 看第二个代码简介,我用getter和setter将fs作为一个属性。
<ContEmpirical xs="0.2 0.3 0.4 0.8" fs="0.2 0.3 0.4 0.8"/>