Hi everyone,

1st of all, thanks to all jibx developers and contributors for such a
great tool.

I'm try to develop a binding to a set of complex XML schemas used in
the banking sector, particularly in the inter-bank messaging domain
(see ISO20022).

I have managed to complete the mapping for the first two schemas but
I've come across a JiBX behaviour that I don't understand. What
follows is a very simplified version of the binding:

<?xml version="1.0" encoding="UTF-8"?>
<binding>

    <mapping name="container" class="com.mycompany.ebatest.Container">
        <namespace uri="urn:eba:scf" default="elements" prefix="scf"/>
        <value name="sender"            field="sender"/>
        <value name="receiver"          field="receiver"/>
        <collection field="bulks" type="java.util.ArrayList"
item-type="com.mycompany.ebatest.Bulk">
            <structure name="bulk"/>
        </collection>
    </mapping>

    <mapping class="com.mycompany.ebatest.Bulk" abstract="true">
        <namespace uri="urn:iso:pacs8" default="elements" prefix="p8"/>
        <structure name="header" field="header">
            <value name="reference"         field="reference"/>
            <structure name="inter-bk-amt"  field="interBankAmount"/>
            <structure name="fin-id"        field="finId" usage="optional"
                       ordered="false" choice="true">
                <value name="id"            field="finId"   usage="optional"/>
                <value name="name"          field="name"    usage="optional"/>
            </structure>
        </structure>
        <structure          field="transaction"/>
    </mapping>

    <mapping name="transaction" class="com.mycompany.ebatest.Transaction">
        <namespace uri="urn:iso:pacs8" default="elements"/>
        <value name="id"                field="id"/>
        <structure name="tx-amt"        field="txAmount"/>
        <!-- here lies the problem -->
        <structure name="payment-type"        field="paymentType">
            <structure name="level">
                <value name="code"            field="level"/>
            </structure>
            <structure name="instrument"      usage="optional">
                <value name="propr"           field="instrument"
usage="optional"/>
            </structure>
        </structure>
    </mapping>

    <mapping class="com.mycompany.ebatest.CurrencyAndAmount" abstract="true"
             value-style="attribute">
        <value name="currency"          field="currency"/>
        <value style="text"             field="amount"/>
    </mapping>

</binding>

The paymentType field of the Transaction class is of class PaymentType:

public class PaymentType {
    public String level;
    public String instrument;
}

while the schema defines the "payment-type" element to be of a
complexType where the first sub-element ("level") is mandatory while
the second ("instrument") is optional. Both in turn are defined as
complexTypes containing only one mandatory element ("code", resp.
"propr").

IOW these are two legal fragments:

<payment-type>
    <level><code>AVG9089345X</code></level>
    <instrument><propr>Proprietary Remittance</propr></instrument>
</payment-type>

<payment-type>
    <level><code>AVG958294AF</code></level>
</payment-type>

The problem is that when I unmarshal and immediately marshal a
document containing the second fragment what I get is the following:

<payment-type>
    <level><code>AVG958294AF</code></level>
    <instrument/>    <!-- WRONG -->
</payment-type>

The problem lies in the empty "instrument" element that is generated
anyway, even when the "instrument" field is null.

I have tried several approaches to solve this problem to no avail.
Can anyone please shed some light on this behaviour?

Thanks in advance!!!!
-- 
Andrea Cisternino, Ferrara, Italy
LinkedIn profile: http://www.linkedin.com/in/andreacisternino
Blog: http://opificiodigitale.wordpress.com
Foto: http://acisternino.smugmug.com

-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
jibx-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/jibx-users

Reply via email to