gpt4 book ai didi

java - JAXB:元素以类型命名,而不是属性命名

转载 作者:太空宇宙 更新时间:2023-11-04 08:58:49 26 4
gpt4 key购买 nike

Web 服务 wsdl 包含以下架构:

<xs:complexType name="DocumentSearchInfo">
<xs:sequence>
...
<xs:element minOccurs="0" name="Industries" nillable="true" type="tns:ListCondition">
<xs:annotation>
<xs:appinfo>
<DefaultValue EmitDefaultValue="false" xmlns="http://schemas.microsoft.com/2003/10/Serialization/" />
</xs:appinfo>
</xs:annotation>
</xs:element>
...
</xs:sequence>
</xs:complexType>

此代码是通过在 NetBeans 6.7 中添加 Web 引用生成的:

@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "DocumentSearchInfo", propOrder = {
"analysts",
"companyIDCondition",
"contributorCondition",
"countries",
"dateRange",
"documentIDCondition",
"documentPageCondition",
"industries",
"keywordCondition",
"languages",
"profileID",
"purchasedOnly",
"regions",
"researchCategories",
"researchProduct"
})

public class DocumentSearchInfo {
...
@XmlElementRef(name = "Industries", namespace = "http://somenshere", type = JAXBElement.class)
protected JAXBElement<ListCondition> industries;
...
}

依次序列化为

<ns2:SearchInfo>
...
<ns2:ListCondition>
<ns2:Values>
<ns3:string>1385</ns3:string>
<ns3:string>1386</ns3:string>
</ns2:Values>
</ns2:ListCondition>
...
</ns2:SearchInfo>

我希望在此 XML 中看到“Industries”,而不是“ListCondition”。

我在 .net 上使用此服务没有任何问题:无论使用什么序列化程序,svcutil 和 wsdl.exe 都可以正常工作,但看起来我完全错过了有关 Java 序列化的一些明显的东西。

有人可以帮忙吗?

最佳答案

已解决。我应该调用 ObjectFactory 的 createDocumentSearchInfoIndustries 方法。与我在 .net 中习惯的非常不同)

关于java - JAXB:元素以类型命名,而不是属性命名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1443863/

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