Is it possible to marshal XML directly onto an existing object and have only specific fields updated?
I would like to only modify certain fields that are requested by the client.
Any pointers ?
Is it possible to marshal XML directly onto an existing object and have only specific fields updated?
I would like to only modify certain fields that are requested by the client.
Any pointers ?
The solution is : Annotations and Reflection. and no there are no libraries for the same. I searched a lot when I was doing this task.
I have done exactly the same thing as you want, I have done my own implementation for this. But it is proprietary so I cannot share.
But to hint you on solution: I have used annotations to mark the fields that are Reloadable and then used Reflection to reload only the parts that are reloadable.
Step 1: Again unmarshal the xml to create a new Object
Step 2: Call the setter methods on the old object with the new values from the newly unmarshalled object.
Hope this helps.
The short answer is no. There is no easy way to customize the jaxb bindings thinking of a generic solution. See JAXB and class instantiation
Another solution (maybe cruder) would be to extract the XML
part you want to process and then execute the unmarshall. See Java How to extract a complete XML block