Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I have JAXB call a method after it has completed unmarshalling an XML file into an object?

Tags:

I am using JAXB to unmarshall an XML file into a Java object -- standard stuff. Once JAXB has completed this, I'd like a method to be called on the newly created object.

Is there a mechanism to do this? I'd prefer the object, not an external entity, do this to keep construction in one place.

Thanks.

like image 695
Elliot Avatar asked Jun 10 '09 15:06

Elliot


1 Answers

You can simple add the following method to your object definition:

void afterUnmarshal(Unmarshaller u, Object parent) {   ... } 

It will be called once the current object has been completely deserialized. See also the documentation about unmarshalling callbacks

like image 68
Robert Avatar answered Sep 27 '22 15:09

Robert