users@jaxb.java.net

Re: Unmarshalling to an existing object?

From: Farrukh Najmi <farrukh_at_wellfleetsoftware.com>
Date: Tue, 05 Feb 2008 08:56:39 -0500

Aleksei Valikov wrote:
> Hi.
>
>
>> In my app I have a JAXB generated binding object instance. The instance
>> may be modified via "edit" actions. The modifications may be saved via
>> "save" action or discarded via "discard" action. I am looking for some
>> way to restore the original state of the JAXB generated binding object
>> from a snapshot of its original state. What would be terrific is if
>> there was some way to unmarshal previously marshalled state to an
>> existing object instance. This would allow me to restore the state on
>> discard.
>>
>> Is there any way to do this? If not, how have others solved similar
>> design issue? TIA for your help.
>>
>
> Take a look at "copyable" plugin from jaxb2-commons. You can
> unmarshall an object an copy its state into another object. You may
> also provide an own "copy builder" which could, for instance, resolve
> conflicts while copying.
>
>

The "copyable" plugin from jaxb2-commons is just what I needed. Thank Lexi.
BTW the plugin is not documented at jaxb2-commons.dev.java.net.

Lastly, when using the plugin I ran into some case of compile errors like:

ValueType.java:94: org.xxx.ValueType is abstract; cannot be instantiated
        final ValueType copy = ((target == null)?new
ValueType():((ValueType) target));

The schema was defined as follows:

<complexType name="ValueType" abstract="true">

Is this a known issue ir shall I file a new issue report?

-- 
Regards,
Farrukh Najmi
Web: http://www.wellfleetsoftware.com