I have these gradle tasks to rund jibx-bind and 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 creates this 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>
And bind creates the jibx*.classes.
Using this file and running this java code creates an unexpected result:
<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 );
}
The problem I have is that the unmarshalled object can be casted to AlgoProfiles but the field profiles has one AlgoProperties object but also a one ClientPanels object.
The ClientPanels object should be set as the field on the AlgoProfiles object and not as a member in the profiles collection.
This worked with java 1.7 and an older jibx version but I have to move to Java 8 and that needs a newer jibx version.
I have no idea why this happens like that.
Update:
When I add the item-type
attribute to the collection tags with the correct type, then unmarshaling works.
Is it possible to tell the BindingGenerator to add these attributes?