我正在从wsdl
生成java类使用cxf / jaxb
和配置<jaxb:globalBindings generateElementProperty="false">
,这给了我直接从 xml 中通过 getter 和 setter 获取元素的优势,而不必实例化 JAXBElement
每次都明确。
我想要访问的一个元素自动生成为 @XmlSeeAlso
.
问题:自动生成的类不包含此类的任何 getter!如果没有创建 getter,我怎样才能接收其中的属性??
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "Fare", propOrder = {
"some",
"props"
})
@XmlSeeAlso({
AnySubType.class
})
@Generated
public class AutoGeneratedClass {
//there is no getAnySubType() method!
//only getters for some, props etc.
}
其中:
@Generated
public class AnySubType
extends AutoGeneratedClass
{
最佳答案
我将尝试解决您提出的问题:
//there is no getAnySubType() method!
不会有的。在父类(super class)上使用返回特定子类实例的方法并不是常见的面向对象实践。
well somehow a few values that I need to get from the xml are inside hte AnySubType, but a getter for that type is missing so I cannot access them...
您需要将 AutoGenerateClass
实例强制转换为 AnySubType
才能访问子类方法。
关于java - 如何从自动生成的@XmlSeeAlso 中获取元素?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27529494/