-
Notifications
You must be signed in to change notification settings - Fork 42
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
There should be a possibility to specify "post-construct" code. #251
Comments
@glassfishrobot Commented |
@glassfishrobot Commented |
@glassfishrobot Commented There should be a possibility to specify a "post-construct" method, which JAXB |
@glassfishrobot Commented |
@glassfishrobot Commented public void afterUnmarshal(Unmarshaller u, Object parent) { // do something } to your java class.. |
@glassfishrobot Commented
|
@glassfishrobot Commented ad 2) maybe, but JAXB provides four "callbacks": beforeMarshal, afterMarshal, And additionally - |
@glassfishrobot Commented public class CustomListener @OverRide Class<?> type = object.getClass(); for (Method m : ReflectionUtils.getAllMethods(type)) { { throw new IllegalStateException( "@PostConstruct used multiple times"); } postConstructMethod = m; if (postConstructMethod != null) {
if (!Modifier.isFinal(postConstructMethod.getModifiers())) { throw new IllegalArgumentException("post construct method [" + postConstructMethod.getName() + "] must be final"); } try { postConstructMethod.setAccessible(true); postConstructMethod.invoke(object); } catch (IllegalAccessException ex) { throw new RuntimeException(ex); } catch (InvocationTargetException ex) { throw new RuntimeException(ex); } } |
@glassfishrobot Commented |
@glassfishrobot Commented |
@glassfishrobot Commented |
@glassfishrobot Commented Please, explain what you mean. |
@glassfishrobot Commented What I think is needed is the ability to operate on objects as they are created. |
@glassfishrobot Commented |
|
There should be a possibility to specify code, which JAXB would call after an
object was unmarshalled (after all fields were set, so that method could use
them). It is not possible to achieve this using the ctor.
This functionality could be made available either by a new annotation
(@XmlPostConstruct or something).
Please see this resource for a possible workaround:
http://stackoverflow.com/questions/1545478/is-there-something-like-postconstruct-for-jaxb-annnotated-classes/1545867#1545867
Environment
Operating System: All
Platform: All
Affected Versions
[2.0 FCS]
The text was updated successfully, but these errors were encountered: