Hi every body,
I'm a beginner of JIBX, I discovered this amazing library 1 week ago. I
hope i'll find some help here :)
My problem is : how to initialize a Arraylist of "Info" class who must
initialize another class"Adress".
I can't modify classes implementation and the xml received.
See below :
*CLASSES :*
*
*
class User(){
String name;
Info[] info;
}
class Info(){
Adress adr;
}
class Adress(){
String street;
String number;
}
*XML:*
*
*
<root>
<user>
<name>my name</name>
<adress>
<number>1234</number>
<street>my street</street>
</adress>
<adress>
<number>555</number>
<street>my street 2</street>
</adress>
</user>
</root>
*BINDING 1:*
*
*
<binding>
<mapping name="root" class="test.User" ordered="false">
<structure name="user" ordered="false" usage="optional"
allow-repeats="true">
<value name="name" field="name" usage="optional" />
<collection name="adress" field="info" ordered="false" usage="optional">
<structure type="test.Info" ordered="false" usage="optional">
<structure field="adr" ordered="false" usage="optional" />
</structure>
</collection>
</structure>
</mapping>
<mapping name="adress" class="test.Adress" ordered="false">
<value name="street" field="street" usage="optional" />
<value name="number" field="number" usage="optional" />
</mapping>
</binding>
*BINDING 2:*
<binding>
<mapping name="root" class="test.User" ordered="false">
<structure name="user" ordered="false" usage="optional"
allow-repeats="true">
<value name="name" field="name" usage="optional" />
<collection name="adress" field="info" ordered="false" usage="optional">
<structure type="test.Info" ordered="false" usage="optional">
<structure field="adr" ordered="false" usage="optional">
<value name="street" field="street" usage="optional" />
<value name="number" field="number" usage="optional" />
</structure>
</structure>
</collection>
</structure>
</mapping>
</binding>
----------------------------------------------------------------------------------------------------------------------
*With binding 1:*
org.jibx.runtime.JiBXException: Expected "adress" end tag, found "number"
start tag (line 5, col 15)
at
org.jibx.runtime.impl.UnmarshallingContext.parsePastCurrentEndTag(UnmarshallingContext.java:731)
at fr.cimut.test.User.JiBX_test_collect_binding_unmarshal_1_1(User.java)
at fr.cimut.test.JiBX_test_collect_bindingUser_access1.unmarshal()
at
org.jibx.runtime.impl.UnmarshallingContext.unmarshalElement(UnmarshallingContext.java:2757)
at
org.jibx.runtime.impl.UnmarshallingContext.unmarshalDocument(UnmarshallingContext.java:2900)
at fr.cimut.test.Test.<init>(Test.java:26)
at fr.cimut.test.Test.main(Test.java:18)
*With the binding 2, only the second adress is returned*
//******************************
IBindingFactory bfact = BindingDirectory.getFactory(User.class);
IUnmarshallingContext uctx = bfact.createUnmarshallingContext();
User user = (User)uctx.unmarshalDocument(new
FileInputStream("resources\\test.xml"), null);
System.out.println(user.getName());
System.out.println(user.getInfo()[0].getAdr().getStreet());
System.out.println(user.getInfo()[1].getAdr().getStreet());
//***************************
--- OUPUT ----
my name
my street 2
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 1
at fr.cimut.test.Test.<init>(Test.java:31)
at fr.cimut.test.Test.main(Test.java:18)
Thanks in advance.
*pym*
------------------------------------------------------------------------------
All the data continuously generated in your IT infrastructure
contains a definitive record of customers, application performance,
security threats, fraudulent activity, and more. Splunk takes this
data and makes sense of it. IT sense. And common sense.
http://p.sf.net/sfu/splunk-novd2d
_______________________________________________
jibx-users mailing list
jibx-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jibx-users