gpt4 book ai didi

java - 如何从自动生成的@XmlSeeAlso 中获取元素?

转载 作者:行者123 更新时间:2023-12-02 05:08:48 28 4
gpt4 key购买 nike

我正在从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/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com