hi dennis,

we will use JiBX for unmarshalling and marshalling, but we will not use both directions for the same data, so your approach to use direction="input" works fine and we're happy that this issue is solved. thanks a lot! this is of course much easier to use than having to write unmarshallers for these classes (the second possible approach to solve this problem).

br,
guenther

Am 31.07.2007 um 03:46 schrieb Dennis Sosnoski:

You've got a couple of problems with this variation. The first is that
when unmarshalling JiBX will reuse an existing object when possible - so
whenever it sees an <address> element it'll call the getAddress method
and just write over the existing values in the object returned. The
second is that if you use this binding for marshalling you'll only get
one Address written out.

Are you only unmarshalling, and not marshalling? If so, you could use a
variation of this approach to handle your collection. Just define your
binding as direction='input', then you don't need to provide get methods
and JiBX will create a new instance of the Address class each time it
sees one of the elements, which is what you want.

  - Dennis

Dennis M. Sosnoski
SOA and Web Services in Java
Training and Consulting
http://www.sosnoski.com - http://www.sosnoski.co.nz
Seattle, WA +1-425-939-0576 - Wellington, NZ +64-4-298-6117



Günther Wieser wrote:
ok, i tried some things out using the following code and binding:

<?xml version="1.0" encoding="ISO-8859-2"?>
<binding>
<mapping name="customer" class="simpledata.Customer"
ordered="false" flexible="true" allow-repeats="true" >
<value name="id" field="id" />
<value name="first" field="firstName" />
<value name="last" field="lastName" />
<structure name="address" ordered="false" type="simpledata.Address"
set-method="addAddress"
get-method="getAddress" factory="simpledata.Address.newInstance"/>
</mapping>
<mapping class="simpledata.Address" abstract="true" flexible="true"
ordered="false">
<value name="id" field="id"/>
<value name="street" field="street" usage="required" nillable="true"/>
<value name="city" field="city" usage="required" nillable="true" />


</mapping>
</binding>

code:
public class Address {



private static Address newInstance() {
Address address = new Address();
System.out.println("Created: " + address);
return address;
}

// #################################################################
// I even use cloning when one address is added to the list of
addresses in Customer!!
// #################################################################
public Address clone() {
Address clone = new Address();
clone.id = new Long(this.id.longValue());
clone.street = this.street;
clone.city = this.city;
return clone;
}


}

XML data:
<?xml version="1.0" encoding="ISO-8859-2"?>
<customer xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";>
<id>1234</id>
<first>Heinz</first>
<last>Prueller</last>
<!-- unused element
<asdasd>asasd</asdasd>-->
<address>
<id>111</id>
<street>Daham 1</street>
  <city xsi:nil="true" />
<!-- unused element
<kasperl>sdasdasd</kasperl>-->
</address>
 <address>
<id>222</id>
<street>Daham 2</street>
<city>2220 Wien</city>

</address>
</customer>


this is the result i get when running the example:
1: Created: [EMAIL PROTECTED] [city=null]]
2: -----------------
3: address was: [EMAIL PROTECTED]
1][city=null]]
4: clone is   : [EMAIL PROTECTED]
1][city=null]]
5: -----------------
6: address was: [EMAIL PROTECTED]
2][city=2220 Wien]]
7: clone is   : [EMAIL PROTECTED]
2][city=2220 Wien]]
8: Result:
[EMAIL PROTECTED] [lastName=Prueller][addresses.size=2 [EMAIL PROTECTED]
2][city=2220
[EMAIL PROTECTED]
2][city=2220 Wien]]]]]

in 1) the instance of Address is created. Why only once? I thought
this will happen with each "address" element?
in 3) you can see what my code receives from JiXB
in 4) you could see the clone I made out of the Address I received
from JiXB (note the different Java IDs after the @ sign)
in 6) you can see that the next Address object I receive from JiXB is
the same object that I cloned, but with different/new values!!! How come?

just to mention: when my XML data would contain even more address
elements, all items of Address objects would have the values from the
last address element.

I'm honestly totally confused. Hope someone can help....

yours desperately,
günther

--
Günther Wieser
creative-it

--------------------------------------------------------------------- ---

--------------------------------------------------------------------- ----
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >>  http://get.splunk.com/
--------------------------------------------------------------------- ---

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


---------------------------------------------------------------------- ---
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >>  http://get.splunk.com/
_______________________________________________
jibx-users mailing list
jibx-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jibx-users





--
Günther Wieser
openForce Information Technology GesmbH
Plenergasse 1
A-1180 Wien

[EMAIL PROTECTED]
http://www.openforce.com








--
Günther Wieser
creative-it
Guglgasse 6/1/11/1
A-1110 Wien
[EMAIL PROTECTED]
http://www.creative-it.com


-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >>  http://get.splunk.com/
_______________________________________________
jibx-users mailing list
jibx-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jibx-users

Reply via email to