Skip to main content

Using JAXB to unmarshal xml to an existing prepopulated object

Please note these java.net forums are being decommissioned and use the new and improved forums at https://community.oracle.com/community/java.
1 reply [Last post]
al_java
Offline
Joined: 2012-11-19

Is there a way to use JAXB to unmarshal source XML to an existing JAXB annotated object containing data (an object that i have previously instantiated and populated with data)? So when I call the unmarshal() method it merges the data in the existing pre-popluated object with data in the source XML? It effect, it updates the Java object with data in the source XML.

It appears I can only unmarshal to an new empty object that JAXB instantiates based on the class I pass in the newInstance() method.

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Glen Mazza

Unsure, but you can probably unmarshal to a new object and then merge it
with the already existing one (possibly a better implementation
anyway). Depending on the data types you're using, Java may have very
efficient algorithms for doing that merging.

Glen

On 11/19/2012 11:47 AM, forums@java.net wrote:
> Is there a way to use JAXB to unmarshal source XML to an existing JAXB
> annotated object containing data (an object that i have previously
> instantiated and populated with data)? So when I call the unmarshal()
> method
> it merges the data in the existing pre-popluated object with data in the
> source XML? It effect, it updates the Java object with data in the source
> XML. It appears I can only unmarshal to an new empty object that JAXB
> instantiates based on the class I pass in the newInstance() method.
>