[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&#39;m a beginner of JIBX, I discovered this \
amazing library 1 week ago. I hope i&#39;ll find some help here \
:)</div><div><br></div><div>My problem is : how to initialize a Arraylist of \
&quot;Info&quot; class who must initialize another class&quot;Adress&quot;. </div> \
<div><br></div><div>I can&#39;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>&lt;root&gt;</div><div> \
&lt;user&gt;</div><div>    &lt;name&gt;my name&lt;/name&gt;</div><div>    \
&lt;adress&gt;</div><div>      &lt;number&gt;1234&lt;/number&gt;</div> <div>      \
&lt;street&gt;my street&lt;/street&gt;</div><div>    &lt;/adress&gt;</div><div>    \
&lt;adress&gt;</div><div>      &lt;number&gt;555&lt;/number&gt;</div><div>      \
&lt;street&gt;my street 2&lt;/street&gt;</div><div>  &lt;/adress&gt;</div><div>  \
&lt;/user&gt;</div><div>&lt;/root&gt;</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>&lt;binding&gt;</div><div><span \
class="Apple-tab-span" style="white-space:pre">	</span>&lt;mapping \
name=&quot;root&quot; class=&quot;test.User&quot; ordered=&quot;false&quot;&gt;</div> \
<div><span class="Apple-tab-span" style="white-space:pre">		</span>&lt;structure \
name=&quot;user&quot; ordered=&quot;false&quot; usage=&quot;optional&quot; \
allow-repeats=&quot;true&quot;&gt;</div><div><span class="Apple-tab-span" \
style="white-space:pre">			</span>&lt;value name=&quot;name&quot; \
field=&quot;name&quot; usage=&quot;optional&quot; /&gt;</div> <div><span \
class="Apple-tab-span" style="white-space:pre">			</span>&lt;collection \
name=&quot;adress&quot; field=&quot;info&quot; ordered=&quot;false&quot; \
usage=&quot;optional&quot;&gt;</div><div><span class="Apple-tab-span" \
style="white-space:pre">				</span>&lt;structure type=&quot;test.Info&quot; \
ordered=&quot;false&quot; usage=&quot;optional&quot;&gt;</div> <div><span \
class="Apple-tab-span" style="white-space:pre">					</span>&lt;structure \
field=&quot;adr&quot; ordered=&quot;false&quot; usage=&quot;optional&quot;  \
/&gt;</div><div><span class="Apple-tab-span" \
style="white-space:pre">				</span>&lt;/structure&gt;</div> <div><span \
class="Apple-tab-span" \
style="white-space:pre">			</span>&lt;/collection&gt;</div><div><span \
class="Apple-tab-span" \
style="white-space:pre">		</span>&lt;/structure&gt;</div><div><span \
class="Apple-tab-span" style="white-space:pre">	</span>&lt;/mapping&gt;</div> \
<div><span class="Apple-tab-span" style="white-space:pre">	</span>&lt;mapping \
name=&quot;adress&quot; class=&quot;test.Adress&quot; \
ordered=&quot;false&quot;&gt;</div><div><span class="Apple-tab-span" \
style="white-space:pre">		</span>&lt;value name=&quot;street&quot; \
field=&quot;street&quot; usage=&quot;optional&quot; /&gt;</div> <div><span \
class="Apple-tab-span" style="white-space:pre">		</span>&lt;value \
name=&quot;number&quot; field=&quot;number&quot; usage=&quot;optional&quot; \
/&gt;</div><div><span class="Apple-tab-span" \
style="white-space:pre">	</span>&lt;/mapping&gt;</div> \
<div>&lt;/binding&gt;</div></div></div><div><div><br></div><div><b><u>BINDING \
2:</u></b></div><div><div>&lt;binding&gt;</div><div><span class="Apple-tab-span" \
style="white-space:pre">	</span>&lt;mapping name=&quot;root&quot; \
class=&quot;test.User&quot; ordered=&quot;false&quot;&gt;</div> <div><span \
class="Apple-tab-span" style="white-space:pre">		</span>&lt;structure \
name=&quot;user&quot; ordered=&quot;false&quot; usage=&quot;optional&quot; \
allow-repeats=&quot;true&quot;&gt;</div><div><span class="Apple-tab-span" \
style="white-space:pre">			</span>&lt;value name=&quot;name&quot; \
field=&quot;name&quot; usage=&quot;optional&quot; /&gt;</div> <div><span \
class="Apple-tab-span" style="white-space:pre">			</span>&lt;collection \
name=&quot;adress&quot; field=&quot;info&quot; ordered=&quot;false&quot; \
usage=&quot;optional&quot;&gt;</div><div><span class="Apple-tab-span" \
style="white-space:pre">				</span>&lt;structure type=&quot;test.Info&quot; \
ordered=&quot;false&quot; usage=&quot;optional&quot;&gt;</div> <div><span \
class="Apple-tab-span" style="white-space:pre">					</span>&lt;structure \
field=&quot;adr&quot; ordered=&quot;false&quot; \
usage=&quot;optional&quot;&gt;</div><div><span class="Apple-tab-span" \
style="white-space:pre">						</span>&lt;value name=&quot;street&quot; \
field=&quot;street&quot; usage=&quot;optional&quot; /&gt;</div> <div><span \
class="Apple-tab-span" style="white-space:pre">						</span>&lt;value \
name=&quot;number&quot; field=&quot;number&quot; usage=&quot;optional&quot; \
/&gt;</div><div><span class="Apple-tab-span" \
style="white-space:pre">					</span>&lt;/structure&gt;</div> <div><span \
class="Apple-tab-span" \
style="white-space:pre">				</span>&lt;/structure&gt;</div><div><span \
class="Apple-tab-span" \
style="white-space:pre">			</span>&lt;/collection&gt;</div><div><span \
class="Apple-tab-span" style="white-space:pre">		</span>&lt;/structure&gt;</div> \
<div><span class="Apple-tab-span" \
style="white-space:pre">	</span>&lt;/mapping&gt;</div><div>&lt;/binding&gt;</div></div \
><div><br></div><div><br></div><div>----------------------------------------------------------------------------------------------------------------------</div>
> 
<div><b>With binding 1:</b></div><div><div>org.jibx.runtime.JiBXException: Expected \
&quot;adress&quot; end tag, found &quot;number&quot; 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.&lt;init&gt;(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(&quot;resources\\test.xml&quot;), 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 \
&quot;main&quot; java.lang.ArrayIndexOutOfBoundsException: 1</div><div><span \
class="Apple-tab-span" style="white-space:pre">	</span>at \
fr.cimut.test.Test.&lt;init&gt;(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