Title: JIBX -- Problem unmarshalling optional elements
just in case anyone else sees this.

I was getting the same Exception.  Didn't understand Joshua's suggestion, at least as it applied to me.

I took out ordered="false" from the top level mapping, and it went away.

now to see if that breaks any of the other crazy stuff I'm trying to do...

cheers,
Linus


Davies, Joshua wrote:

Hm – this may be a bug in jibx (since I believe it should have given you a compile error on the binding), but the simple solution is to move the element name down into the mapping itself rather than in the structure declaration.  Make the following two changes:

 

5:     <structure field="address" usage="optional"  ordered="false" flexible="true" />

 

10:  <mapping abstract="true" name="address" class="jibxtest.Address" flexible="true" ordered="false">

 

As you can see, all I’ve done here is moved “name” from line 5 down to line 10.  I’m assuming that the field “address” of class “Person” is actually declared as being of type “jibxtest.Address” – if it’s not, you need to add a type=”jibxtest.Address” to line 5 so that the binding runtime can locate the correct mapping.

 

Also, why is the jibxtest.Address mapping declared “abstract” below?  Do you have subclasses for it in the actual binding?  If not, you should remove the abstract=”true” (I was actually a little surprised that line 10, above, compiled at all); if so, you’ll want to define the name elements on the subclasses themselves.

 


From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]] On Behalf Of Janga, Sowjanya
Sent: Tuesday, July 03, 2007 8:35 AM
To: 'jibx-users@lists.sourceforge.net'
Subject: [jibx-users] JIBX -- Problem unmarshalling optional elements

 

Hi,
      I have a binding that is meant to unmarshal optional elements. I'am getting an error while unmarshalling an optional element that is coming in empty.

      I am using JIBX version 1.15.
      I have been struggling with this issue for sometime. I would really appreciate any help.

My binding file
<?xml version="1.0"?>
<binding track-source="true"
         direction="input" >
        <mapping name="person" class="jibxtest.Person"
             flexible="true" ordered="false">
                <value name="name" field="name"/>
                <structure name="residential" flexible="true" ordered="false" >
                   <structure name="address" field="address"
                              usage="optional"  ordered="false" flexible="true" />
                   <value field="email" name="email" usage="optional"/>
                </structure>
        </mapping>
        <mapping abstract="true" class="jibxtest.Address" flexible="true" ordered="false">
                <value field="street" name="street" usage="optional" />
                <value field="zip" name="zip" usage="optional" />
                <value field="city" name="city" usage="optional"  />
        </mapping>
</binding>

     Although I have address as an optional element, I'am getting an error saying.

      org.jibx.runtime.JiBXException: Missing required element "(unknown name, position 0 in binding structure)"(line 4, col 21)

     [java] at org.jibx.runtime.impl.UnmarshallingContext.throwNameException(UnmarshallingContext.java:315)
     [java] at jibxtest.Address.JiBX_binding_unmarshal_1_1(Address.java)
     [java] at jibxtest.Person.JiBX_binding_unmarshal_1_1(Person.java)
     [java] at jibxtest.JiBX_bindingPerson_access1.unmarshal()
     [java] at org.jibx.runtime.impl.UnmarshallingContext.unmarshalElement(UnmarshallingContext.java:2537)
     [java] at org.jibx.runtime.impl.UnmarshallingContext.unmarshalDocument(UnmarshallingContext.java:2694)
     [java] at jibxtest.JiBXTest.main(JiBXTest.java:23)

     My input XML is
<person>
        <name>John</name>
        <residential>
        <address></address>
        <email></email>
        </residential>
</person>


------------------------------------------------------------------------- This SF.net email is sponsored by DB2 Express Download DB2 Express C - the FREE version of DB2 express and take control of your XML. No limits. Just data. Click to get it now. http://sourceforge.net/powerbar/db2/

_______________________________________________ jibx-users mailing list jibx-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/jibx-users



-------------------------------------------------------------------------
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
jibx-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jibx-users

Reply via email to