(resending after sf.net email problems)
Hi Jon,
JiBX will reuse existing objects when unmarshalling in preference to
creating a new instance. So with a structure like this:
class A {
private B b;
}
class B {
private String s;
}
and a binding:
<mapping name="a" class="A">
<structure name="b" field="b" usage="optional">
<value name="s" field="s"/>
</structure>
</mapping>
unmarshalling the document:
<a><b><s>some text</s></b></a>
into an instance of A which already has a B value set will keep the same
B and replace the previous value of the String s within that B. But
unmarshalling the document:
<a/>
will set the B reference to null.
It sounds like you want to keep existing values unless otherwise
specified in the XML. As Thomas suggested, you can do this by using a
set-method rather than telling JiBX to store directly to the field. The
set-method can check if JiBX is storing a null value (or whatever the
default is, in the case of a primitive value), and if so just keep the
existing value.
You don't generally need to use a factory method to reuse existing
objects, since JiBX will try to do this in any case if a reference is
non-null.
- 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
Jon Little wrote:
> Hi
>
> Does anyone have an example binding and code snippet which illustrates
> the below technique of updating an existing object?
>
> Thanking you in advance
>
> Jon
>
>> Thomas Jones-Low
>> Fri, 09 May 2008 07:16:50 -0700
>>
>> Using a existing object will require the use of the Factory
>> attribute
>> for the binding. This is a static method which returns the instance to
>> be worked on.
>>
>> The original values to be kept will need a set-method rather than
>> the
>> default setter, to check for the null value and not update them.
>>
>> --
>> Thomas Jones-Low Softstart Services Inc.
>> [EMAIL PROTECTED] JobScheduler for Oracle
>> Ph: 802-398-1012 http://www.softstart.com
>>
>> Tudor Olteanu wrote:
>> > Hi,
>> >
>> > I want Unmarshall to update an existing object instead of creating a new
>> > one and also to not overwrite the exiting values for optional fields
>> > that are missing.
>> >
>> > I've cast my object to IUnmarshallable and then called
>> > unmarshal(UnmarshallingContext) on my instance but, for optional fields
>> > that are missing in xml, unmarshall replace my instance's existing
>> > values with null values.
>> >
>> > Please let me know if there is a solution to preserve the original
>> > values for optional fields that are missing.
>> >
>> > Thanks,
>> > Tudor
>> >
>> >
>
> ------------------------------------------------------------------------
>
> -------------------------------------------------------------------------
> 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
> [email protected]
> 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
[email protected]
https://lists.sourceforge.net/lists/listinfo/jibx-users