[prev in list] [next in list] [prev in thread] [next in thread]
List: jibx-users
Subject: [jibx-users] Collection Mapping
From: Pierre-yves motreff <pymotreff () gmail ! com>
Date: 2011-11-28 15:24:38
Message-ID: CAKnC_t4FBPcMMXDYyAjZpBF805JwfD5wLwdQHrHBmWB+_L_J5w () mail ! gmail ! com
[Download RAW message or body]
[Attachment #2 (multipart/alternative)]
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*
[Attachment #5 (text/html)]
Hi every body,<div><br></div><div>I'm a beginner of JIBX, I discovered this \
amazing library 1 week ago. I hope i'll find some help here \
:)</div><div><br></div><div>My problem is : how to initialize a Arraylist of \
"Info" class who must initialize another class"Adress". </div> \
<div><br></div><div>I can't modify classes implementation and the xml \
received.</div><div><br></div><div>See below \
:</div><div><br></div><div><div><u><b>CLASSES \
:</b></u></div><div><u><b><br></b></u></div><div>class User(){</div> <div>String \
name;</div><div> Info[] info;</div><div>}</div><div><br></div><div>class \
Info(){</div><div>Adress adr;</div><div>}</div><div><br></div><div>class \
Adress(){</div><div>String street;</div><div>String number;</div> \
<div>}</div><div><br></div><div><b><u>XML:</u></b></div><div><b><u><br></u></b></div><div><div><root></div><div> \
<user></div><div> <name>my name</name></div><div> \
<adress></div><div> <number>1234</number></div> <div> \
<street>my street</street></div><div> </adress></div><div> \
<adress></div><div> <number>555</number></div><div> \
<street>my street 2</street></div><div> </adress></div><div> \
</user></div><div></root></div></div><div><br></div><div><br></div><div><b><u>BINDING \
1:</u></b></div><div><b><u><br></u></b></div><div><div><div><binding></div><div><span \
class="Apple-tab-span" style="white-space:pre"> </span><mapping \
name="root" class="test.User" ordered="false"></div> \
<div><span class="Apple-tab-span" style="white-space:pre"> </span><structure \
name="user" ordered="false" usage="optional" \
allow-repeats="true"></div><div><span class="Apple-tab-span" \
style="white-space:pre"> </span><value name="name" \
field="name" usage="optional" /></div> <div><span \
class="Apple-tab-span" style="white-space:pre"> </span><collection \
name="adress" field="info" ordered="false" \
usage="optional"></div><div><span class="Apple-tab-span" \
style="white-space:pre"> </span><structure type="test.Info" \
ordered="false" usage="optional"></div> <div><span \
class="Apple-tab-span" style="white-space:pre"> </span><structure \
field="adr" ordered="false" usage="optional" \
/></div><div><span class="Apple-tab-span" \
style="white-space:pre"> </span></structure></div> <div><span \
class="Apple-tab-span" \
style="white-space:pre"> </span></collection></div><div><span \
class="Apple-tab-span" \
style="white-space:pre"> </span></structure></div><div><span \
class="Apple-tab-span" style="white-space:pre"> </span></mapping></div> \
<div><span class="Apple-tab-span" style="white-space:pre"> </span><mapping \
name="adress" class="test.Adress" \
ordered="false"></div><div><span class="Apple-tab-span" \
style="white-space:pre"> </span><value name="street" \
field="street" usage="optional" /></div> <div><span \
class="Apple-tab-span" style="white-space:pre"> </span><value \
name="number" field="number" usage="optional" \
/></div><div><span class="Apple-tab-span" \
style="white-space:pre"> </span></mapping></div> \
<div></binding></div></div></div><div><div><br></div><div><b><u>BINDING \
2:</u></b></div><div><div><binding></div><div><span class="Apple-tab-span" \
style="white-space:pre"> </span><mapping name="root" \
class="test.User" ordered="false"></div> <div><span \
class="Apple-tab-span" style="white-space:pre"> </span><structure \
name="user" ordered="false" usage="optional" \
allow-repeats="true"></div><div><span class="Apple-tab-span" \
style="white-space:pre"> </span><value name="name" \
field="name" usage="optional" /></div> <div><span \
class="Apple-tab-span" style="white-space:pre"> </span><collection \
name="adress" field="info" ordered="false" \
usage="optional"></div><div><span class="Apple-tab-span" \
style="white-space:pre"> </span><structure type="test.Info" \
ordered="false" usage="optional"></div> <div><span \
class="Apple-tab-span" style="white-space:pre"> </span><structure \
field="adr" ordered="false" \
usage="optional"></div><div><span class="Apple-tab-span" \
style="white-space:pre"> </span><value name="street" \
field="street" usage="optional" /></div> <div><span \
class="Apple-tab-span" style="white-space:pre"> </span><value \
name="number" field="number" usage="optional" \
/></div><div><span class="Apple-tab-span" \
style="white-space:pre"> </span></structure></div> <div><span \
class="Apple-tab-span" \
style="white-space:pre"> </span></structure></div><div><span \
class="Apple-tab-span" \
style="white-space:pre"> </span></collection></div><div><span \
class="Apple-tab-span" style="white-space:pre"> </span></structure></div> \
<div><span class="Apple-tab-span" \
style="white-space:pre"> </span></mapping></div><div></binding></div></div \
><div><br></div><div><br></div><div>----------------------------------------------------------------------------------------------------------------------</div>
>
<div><b>With binding 1:</b></div><div><div>org.jibx.runtime.JiBXException: Expected \
"adress" end tag, found "number" start tag (line 5, col \
15)</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>at \
org.jibx.runtime.impl.UnmarshallingContext.parsePastCurrentEndTag(UnmarshallingContext.java:731)</div>
<div><span class="Apple-tab-span" style="white-space:pre"> </span>at \
fr.cimut.test.User.JiBX_test_collect_binding_unmarshal_1_1(User.java)</div><div><span \
class="Apple-tab-span" style="white-space:pre"> </span>at \
fr.cimut.test.JiBX_test_collect_bindingUser_access1.unmarshal()</div> <div><span \
class="Apple-tab-span" style="white-space:pre"> </span>at \
org.jibx.runtime.impl.UnmarshallingContext.unmarshalElement(UnmarshallingContext.java:2757)</div><div><span \
class="Apple-tab-span" style="white-space:pre"> </span>at \
org.jibx.runtime.impl.UnmarshallingContext.unmarshalDocument(UnmarshallingContext.java:2900)</div>
<div><span class="Apple-tab-span" style="white-space:pre"> </span>at \
fr.cimut.test.Test.<init>(Test.java:26)</div><div><span class="Apple-tab-span" \
style="white-space:pre"> </span>at fr.cimut.test.Test.main(Test.java:18)</div> \
</div><div><br></div><div><b>With the binding 2, only the second adress is \
returned</b></div><div><br></div><div>//******************************</div><div><div>IBindingFactory \
bfact = BindingDirectory.getFactory(User.class);</div> <div><span \
class="Apple-tab-span" style="white-space:pre"> </span>IUnmarshallingContext uctx = \
bfact.createUnmarshallingContext();</div><div><span class="Apple-tab-span" \
style="white-space:pre"> </span>User user = (User)uctx.unmarshalDocument(new \
FileInputStream("resources\\test.xml"), null);</div> <div><span \
class="Apple-tab-span" style="white-space:pre"> </span></div><div><span \
class="Apple-tab-span" \
style="white-space:pre"> </span>System.out.println(user.getName());</div><div><span \
class="Apple-tab-span" style="white-space:pre"> </span></div> <div><span \
class="Apple-tab-span" \
style="white-space:pre"> </span>System.out.println(user.getInfo()[0].getAdr().getStreet());</div><div><span \
class="Apple-tab-span" \
style="white-space:pre"> </span>System.out.println(user.getInfo()[1].getAdr().getStreet());</div>
</div><div>//***************************</div><div>--- OUPUT \
----</div><div><div><div>my name</div><div>my street 2</div><div>Exception in thread \
"main" java.lang.ArrayIndexOutOfBoundsException: 1</div><div><span \
class="Apple-tab-span" style="white-space:pre"> </span>at \
fr.cimut.test.Test.<init>(Test.java:31)</div> <div><span class="Apple-tab-span" \
style="white-space:pre"> </span>at \
fr.cimut.test.Test.main(Test.java:18)</div></div></div><div><br></div><div><br></div><div>Thanks \
in advance.</div><br> </div></div><div><br></div><div><b><i>pym</i></b></div>
------------------------------------------------------------------------------
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
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic