2012-06-19 50 views
3

鑑於以下注釋jaxb,我可以使用@XmlJavaTypeAdapter與@XmlElements?

因爲一些有趣的傳統邏輯
@XmlElements({ 
@XmlElement(name = "first", type = First.class), 
@XmlElement(name = "second", type = Second.class), 
@XmlElement(name = "third", type = Third.class), 
@XmlElement(name = "fourth", type = Fourth.class), 
@XmlElement(name = "fifth", type = Fifth.class), 
@XmlElement(name = "sixth", type = Sixth.class), 
@XmlElement(name = "seventh", type = Seventh.class)}) 
private List<Dimension> dimensions = new ArrayList<>(); 

而且,我需要爲Third.class的適配器。

@XmlJavaTypeAdapter(ThirdAdapter.class) 
public class Third implements Dimension 

但是,ThirdAdapter似乎永遠不會被調用。 @XmlJavaTypeAdapter是否與@XmlElements兼容?還是有更好的解決方案呢?

回答

2

備註:我是EclipseLink JAXB (MOXy)的領導者和JAXB (JSR-222)專家組的成員。

這似乎是JAXB reference implementation中的一個錯誤。這也是bugEclipseLink JAXB (MOXy),但我們已經在我們的EclipseLink 2.4.0流中修復了它。您可以從以下位置下載候選發佈版:

jaxb.properties

要使用莫西爲您的JAXB提供者,你需要添加一個在名爲jaxb.properties文件與您的域模型相同的包含以下條目的域:

javax.xml.bind.context.factory=org.eclipse.persistence.jaxb.JAXBContextFactory 
+0

感謝您的回答。我希望在標準的JAXB庫中有一個解決方案,但是如果我發現更多的錯誤,我一定會給moxy一個嘗試。現在,這是我遇到的唯一問題,我能夠清除代碼以刪除對適配器的需求。 –

+0

@PresidentComacho - MOXy是一個標準的JAXB(JSR-222)庫,它通過了與參考實現相同的Java EE一致性測試。 –

+0

這個問題是否解決了Java 7_40提供的當前jaxb實現?我沒有找到這個bug的bug跟蹤條目。你知道是否曾經創建過錯誤跟蹤器條目? –

相關問題