提问人:buyufix 提问时间:11/10/2023 更新时间:11/10/2023 访问量:21
JAXB 类生成类型不匹配
JAXB Class Generation Type Mismatching
问:
我正在创建一个SOAP服务,但我遇到了一个问题,我找不到原因和解决方案。
这是我在下面看到的 .xsd 文件中的请求。如您所见,有些首字母故意大写和小写。
<xs:schema elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:tns="http://tempuri.org/"
targetNamespace="http://tempuri.org/"
xmlns:jaxb="http://java.sun.com/xml/ns/jaxb">
<xs:element name="Deneme">
<xs:complexType>
<xs:sequence>
<xs:element name="count" type="xs:int"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="CustomerRequest">
<xs:complexType>
<xs:sequence>
<xs:element name="CustomerName" type="xs:string" />
<xs:element name="Age" type="xs:int" />
<xs:element name="YearlyIncome" type="xs:long" />
<xs:element name="cibilScore" type="xs:int" />
<xs:element name="employmentMode" type="xs:string" />
<xs:element ref="tns:Deneme"/>
</xs:sequence>
</xs:complexType>
</xs:element>
使用 JAXB 生成类后:
客户请求.java
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "", propOrder = {
"customerName",
"age",
"yearlyIncome",
"cibilScore",
"employmentMode",
"deneme"
})
@XmlRootElement(name = "CustomerRequest")
public class CustomerRequest {
@XmlElement(name = "CustomerName", required = true)
protected String customerName;
@XmlElement(name = "Age")
protected int age;
@XmlElement(name = "YearlyIncome")
protected long yearlyIncome;
protected int cibilScore;
@XmlElement(required = true)
protected String employmentMode;
@XmlElement(name = "Deneme", required = true)
protected Deneme deneme;
// getter and setters
}
如您所见,@XmlElement与 xsd 文件相同。但是,propOrder 值以小写开头。它给我带来了以下问题:当我尝试使用SoapUI发送请求时,这种情况问题阻止了请求。
如果我像这样发送请求,它可以工作:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tem="http://tempuri.org/">
<soapenv:Header/>
<soapenv:Body>
<tem:CustomerRequest>
<customerName>5</customerName>
<age>5</age>
<yearlyIncome>5</yearlyIncome>
<cibilScore>5</cibilScore>
<employmentMode>5</employmentMode>
<deneme>
<count>55</count>
</deneme>
</tem:CustomerRequest>
</soapenv:Body>
</soapenv:Envelope>
但是,在下文中,它无法访问以大写开头的元素。
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tem="http://tempuri.org/">
<soapenv:Header/>
<soapenv:Body>
<tem:CustomerRequest>
<CustomerName>5</CustomerName>
<Age>5</Age>
<YearlyIncome>5</YearlyIncome>
<cibilScore>5</cibilScore>
<employmentMode>5</employmentMode>
<Deneme>
<count>55</count>
</Deneme>
</tem:CustomerRequest>
</soapenv:Body>
</soapenv:Envelope>
我该如何解决这个问题?
我想了解解决方案和导致此问题的问题。
答: 暂无答案
评论