I have an xsd generated from a set of existing java classes and currently it successfully unmarshalls XML messages into the object as expected, however what I'd like the ability to do is where I have an existing instance of the Object have the unmarshaller simply update the fields that are contained within the message passed to it
for example (forgive any syntax errors here its just off the top of my head)
If I had an annotated class Book with numerous fields, title, author, published etc and corresponding generated xsd, alot of the fields set to being not required I'd like to be able if I received the following xml
<Book>
<title>Dummys guide to JAXB</title>
</Book>
rather than simply create an new Book instance with only the title set apply this to an existing instance as an update, so simply setting the title variable on that instance.
JAXB can't do that for you, no. However, what you could do is use JAXB to unmarshal your XML document on to a new object, and then reflectively copy the properties of the new object on to your existing one.
Commons BeanUtils provides a mechanism for this, such as the BeanUtils.copyProperties
method. I'm not sure if this does deep-copies, though.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With