在完成将 XML 文件解组为对象后,如何让 JAXB 调用方法? [英] How can I have JAXB call a method after it has completed unmarshalling an XML file into an object?

查看:38
本文介绍了在完成将 XML 文件解组为对象后,如何让 JAXB 调用方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 JAXB 将 XML 文件解组为 Java 对象——标准的东西.JAXB 完成此操作后,我希望在新创建的对象上调用一个方法.

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.

谢谢.

推荐答案

为了能够在解组后执行代码,你需要Unmarshaller-Listener

To be able to execute code after unmarshalling took place, you need an Unmarshaller-Listener

但是,我不确定,如果监听器是在属性设置或之前.

注意:监听器自 JAXB-2.0 (JDK-6)

NOTE: The listener is available since JAXB-2.0 (JDK-6)

这篇关于在完成将 XML 文件解组为对象后,如何让 JAXB 调用方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆