I'm having a problem where I've got an optional attribute defined on an
optional element like this....

    <mapping class="Wrapper" name="wrapper">
          <structure field="policy" name="Policy" map-as="IPolicyType"
usage="optional" />
    </mapping>

    <mapping class="IPolicyType" type-name="IPolicyType"
             abstract="true" factory="Factory.getPolicyType">

        <structure name="ApplicationInfo"
                        get-method="getApplicationInfo"
set-method="setApplicationInfo"
                        map-as="IApplicationInfoType" usage="optional" />

        <value name="BankId"
                  get-method="getBankId" set-method="setBankId"
                  usage="optional" style="attribute" />

        <value name="CarrierId"
                 get-method="getCarrierId"  set-method="setCarrierId"
               usage="optional" style="attribute" />
    </mapping>

  Obviously a simplified example, but the idea is that I should be able to
have an instance document like this:

<wrapper><Policy><ApplicationInfo>...</ApplicationInfo></Policy></wrapper>


The problem I'm running into is this XML will not unmarshal unless at least
one of the optional attributes on Policy is defined.  It doesn't matter if
it's BankId or CarrierId, but one of them must be there for this binding to
work.  Marshalling works fine with or without the Policy attributes defined.

If I make Policy required in the wrapper mapping, unmarshalling works as
expected without any attributes on Policy.  It seems to be the combination
of optional attributes on a mapping that is itself optional.


The stack trace I get when I do try to unmarshal is this:
org.jibx.runtime.JiBXException: Expected "Policy" end tag, found
"ApplicationInfo" start tag (line 4, col 31)
    at org.jibx.runtime.impl.UnmarshallingContext.parsePastCurrentEndTag(
UnmarshallingContext.java:792)
    at com.conseco.codegen.generated.Wrapper.JiBX_binding_unmarshal_1_1(
Wrapper.java)
    at com.conseco.codegen.generated.JiBX_bindingWrapper_access1.unmarshal()
    at org.jibx.runtime.impl.UnmarshallingContext.unmarshalElement(
UnmarshallingContext.java:2537)
    at org.jibx.runtime.impl.UnmarshallingContext.unmarshalDocument(
UnmarshallingContext.java:2694)
    at com.conseco.codegen.generated.TestHarness.main(TestHarness.java:34)

I used JAD to decompile the Wrapper class to take a look at the
JiBX_binding_unmarshal_1_1 method, and it gave me this.

    public final Wrapper JiBX_binding_unmarshal_1_1(UnmarshallingContext
arg1)
        throws JiBXException
    {
        arg1.pushTrackedObject(this);
        this;
        if(arg1.isAt(null, "Policy"))
        {
            arg1.parseToStartTag(null, "Policy");
            policy = (arg1.hasAttribute(null, "BankId") ||
arg1.hasAttribute(null,
"CarrierId")) ?

JiBX_MungeAdapter.JiBX_binding_unmarshalAttr_1_0(policy != null ?

policy :

JiBX_MungeAdapter.JiBX_binding_newinstance_1_0(arg1), arg1)
                        : null;
            arg1.parsePastStartTag(null, "Policy");
            if(policy != null)
                JiBX_MungeAdapter.JiBX_binding_unmarshal_1_2(policy, arg1);
            arg1.parsePastCurrentEndTag(null, "Policy");
        } else
        {
            policy = (IPolicyType)null;
        }
        arg1.popObject();
        return this;
    }

Hopefully gmail doesn't mess up the formatting too bad on that!  It looks
like this code is explicitly checking for the existence of those two
attributes and if they're not found, setting policy to null!  The binding
does have the attributes set as optional, so I'm confused as to why this is
happening!

I apologize if this too much detail for what is hopefully a solution, but
I'm not sure how else to tweak the binding to get what I'm after!

Thanks,
Zach Paul
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
jibx-users mailing list
jibx-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jibx-users

Reply via email to