且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

具有相同名称的Jaxb对象

更新时间:2023-01-16 22:29:42

真的,我要做的第一件事是消除问题的来源 - 有两个不同的JAXB类同名。对于你和那些必须维护代码的人来说,这样的情况肯定会引起头痛。

Really, the first thing I would try to do is eliminate the source of the problem - having two different JAXB classes with the same name. A situation like that is bound to cause headaches, for you and for the people who have to maintain your code.

如果这是不可能的......也许你可以编写另一个子类叫EveryBar,总是解开它。 EveryBar将包含每个其他Bar子类的所有字段。然后,您将在对象树上执行一个后处理步骤,该步骤将检查EveryBar,并将其交换为适合的任何类型的实例。是的,这是一个丑陋的解决方案,但它只比链接中的那个稍差。

If that's impossible... Maybe you could write another subclass called EveryBar, and always unmarshall to that. EveryBar would contain all the fields of every other Bar subclass. Then you'd have a post-processing step on your object tree that would examine the EveryBar, and swap it for an instance of whatever type is appropriate. Yeah, it's an ugly solution, but it's only slightly worse than the one from your link.