gpt4 book ai didi

java - 为什么这个 jibx 绑定(bind)没有像 binding.xml 中指定的那样解码?

转载 作者:行者123 更新时间:2023-12-03 06:12:15 24 4
gpt4 key购买 nike

我有这些 gradle 任务来运行 jibx-bind 和 jibx-bindgen:

dependencies {
compile 'org.jibx:jibx-run:1.2.+'

jibx 'org.jibx:jibx-bind:1.2.+'
jibx 'org.jibx:jibx-run:1.2.+'
jibx 'xpp3:xpp3:1.1.3.4-RC8'
jibx 'org.apache.bcel:bcel:6.0-SNAPSHOT'
}

task bindGen(type: JavaExec) {
main = 'org.jibx.binding.BindingGenerator'
classpath configurations.jibx
classpath sourceSets.main.runtimeClasspath
args 'com.rwe.amm.server.profile.AlgoProfiles'
args 'com.rwe.amm.server.profile.AlgoProperties'
args 'com.rwe.amm.server.profile.AlgoProperty'
args 'com.rwe.amm.server.profile.ClientPosition'
args 'com.rwe.amm.server.profile.ClientPanels'
args 'com.rwe.amm.shared.model.AlgoGenericContractPanel'
args 'com.rwe.amm.shared.model.Property'
}

task bind(type: JavaExec) {
classpath configurations.jibx
classpath sourceSets.main.runtimeClasspath
main = 'org.jibx.binding.Compile'
args projectDir.path + '/binding.xml'
}

bindGen 创建这个 binding.xml:

<?xml version="1.0" encoding="UTF-8"?>
<binding value-style="attribute">
<mapping class="com.rwe.amm.server.profile.AlgoProfiles" name="algo-profiles">
<collection field="profiles" usage="optional" factory="org.jibx.runtime.Utility.arrayListFactory"/>
<collection field="thresholdProperties" usage="optional" factory="org.jibx.runtime.Utility.arrayListFactory"/>
<collection field="fieldDefaultProperties" usage="optional" factory="org.jibx.runtime.Utility.arrayListFactory"/>
<structure field="clientPosition" usage="optional"/>
<structure field="clientPanels" usage="optional"/>
</mapping>
<mapping class="com.rwe.amm.server.profile.AlgoProperties" name="algo-properties">
<value style="element" name="contract" field="contract" usage="optional"/>
<collection field="algoProperties" usage="optional" factory="org.jibx.runtime.Utility.arrayListFactory"/>
</mapping>
<mapping class="com.rwe.amm.server.profile.AlgoProperty" name="algo-property">
<value style="element" name="key" field="key" usage="optional"/>
<value style="element" name="value" field="value" usage="optional"/>
</mapping>
<mapping class="com.rwe.amm.server.profile.ClientPosition" name="client-position">
<value name="xpos" field="xpos"/>
<value name="ypos" field="ypos"/>
<value name="width" field="width"/>
<value name="height" field="height"/>
</mapping>
<mapping class="com.rwe.amm.server.profile.ClientPanels" name="client-panels">
<value name="main-quoting-panel-collapsed" field="mainQuotingPanelCollapsed"/>
<value name="spreads-panel-collapsed" field="spreadsPanelCollapsed"/>
<value name="manual-spreads-swaps-panel-collapsed" field="manualSpreadsSwapsPanelCollapsed"/>
<collection field="genericContractPanels" usage="optional" factory="org.jibx.runtime.Utility.arrayListFactory"/>
</mapping>
<mapping class="com.rwe.amm.shared.model.AlgoGenericContractPanel" name="algo-generic-contract-panel">
<value style="element" name="contract" field="contract" usage="optional"/>
<value style="element" name="contract-panel-id" field="contractPanelId" usage="optional"/>
<value style="element" name="algo-type" field="algoType" usage="optional"/>
<value name="skew-value" field="skewValue" usage="optional"/>
<value name="manual-value" field="manualValue" usage="optional"/>
<value style="element" name="benchmark-contract" field="benchmarkContract" usage="optional"/>
</mapping>
<mapping class="com.rwe.amm.shared.model.Property" name="property">
<value style="element" name="name" field="name" usage="optional"/>
<value style="element" name="value" field="value" usage="optional"/>
<value style="element" name="description" field="description" usage="optional"/>
</mapping>
</binding>

并绑定(bind)创建 jibx*.classes。

使用此文件并运行此 java 代码会产生意想不到的结果:

<algo-profiles>
<algo-properties>
<contract>PEAK YEAR 4,PEAK YEAR 4</contract>
<algo-property>
<key>ARBITRAGE_MANUAL</key>
<value>0.000</value>
</algo-property>
<algo-property>
<key>TIME_MANUAL</key>
<value>50.180</value>
</algo-property>
<algo-property>
<key>DE Mid</key>
<value>n/a</value>
</algo-property>
<algo-property>
<key>SETBASPREAD</key>
<value>MM</value>
</algo-property>
<algo-property>
<key>PRICING</key>
<value>0.000</value>
</algo-property>
</algo-properties>
<client-panels main-quoting-panel-collapsed="true" spreads-panel-collapsed="true" manual-spreads-swaps-panel-collapsed="true"/>
</algo-profiles>

public class AlgoProfiles {
public List<AlgoProperties> profiles;
public List<Property> thresholdProperties;
public List<Property> fieldDefaultProperties;
public ClientPosition clientPosition;
public ClientPanels clientPanels;
}

public boolean read() throws JiBXException {
IBindingFactory bfact = BindingDirectory.getFactory(com.rwe.amm.server.profile.AlgoProfiles.class);
IUnmarshallingContext uctx = bfact.createUnmarshallingContext();

try {
FileInputStream in = new FileInputStream(_profilesLocation + _user + ".xml");
Object obj = uctx.unmarshalDocument(in, null);
setAlgoProfiles((AlgoProfiles)obj);

if ( getAlgoProfiles() == null ) {
logger.warn("... );
return false;
}

if ( getAlgoProfiles() != null && getAlgoProfiles().profiles != null ) {
for ( AlgoProperties algoProperties : getAlgoProfiles().profiles ) {
algoProperties.contract = RollingContractFacade.adapt(algoProperties.contract).getContract();
}
}
} catch ( FileNotFoundException fnfe ) {
logger.warn("... );
}
return ( getAlgoProfiles() != null );
}

我遇到的问题是未编码的对象可以转换为 AlgoProfiles 但字段配置文件有一个 AlgoProperties 对象,但也有一个 ClientPanels 对象。

ClientPanels 对象应设置为 AlgoProfiles 对象上的字段,而不是配置文件集合中的成员。

这适用于 java 1.7 和较旧的 jibx 版本,但我必须迁移到 Java 8 并且需要更新的 jibx 版本。

我不知道为什么会这样。

更新:

当我添加 item-type属性到具有正确类型的集合标签,然后解码工作。

是否可以告诉 BindingGenerator 添加这些属性?

最佳答案

通过将我的任务更改为此解决了我所有的问题:

dependencies {
jibx 'org.jibx:jibx-tools:1.2.+'
}

task bindGen(type: JavaExec) {
main = 'org.jibx.binding.generator.BindGen'
classpath configurations.jibx
classpath sourceSets.main.runtimeClasspath
args '-m'
args 'com.rwe.amm.server.profile.AlgoProfiles'
}

关于java - 为什么这个 jibx 绑定(bind)没有像 binding.xml 中指定的那样解码?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33733235/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com