[英]Unmarshalling maxOccurs unbounded elements having attributes through jaxb
[英]JAXB XmlElement maxOccurs Issue with Array elements
我在下面的getter方法級別XmlElement注釋中使用了從Java類生成xsd的方法。
@XmlElement(type = Integer.class,required = true)
public int [] getTestArrayInt(){....}
生成的XML元素:
<xsd:element name="testArrayInt" type="xsd:int"/>
minOccurs的默認值為1。因此,此處未顯示。 但是缺少為數組元素列出的maxOccurs =“ unbounded” 。 Soap UI希望為數組元素提供maxOccurs =“ unbounded”。 結果,在Soap UI中,此元素未被視為數組。
當我從注釋中刪除type = Integer.class時 ,我開始在XML中獲取maxOccurs =“ unbounded” 。
@XmlElement(required = true)在元素下面生成:
<xsd:element name="testArrayInt" type="xsd:int" maxOccurs="unbounded"/>
但我特別需要這種類型的基本數據類型。 如果沒有在注釋中輸入類型 ,則對於不需要的元素(即未設置required = true) , minOccurs = 1會丟失。
有人可以幫我嗎?
注意:我是EclipseLink JAXB(MOXy)的負責人,並且是JAXB(JSR-222)專家組的成員。
您描述的問題似乎出現在EclipseLink JAXB(MOXy)中,但沒有出現在JAXB參考實現中。 MOXy是WebLogic 12.1.1中的默認JAXB提供程序(請參閱: http ://blog.bdoughan.com/2011/12/eclipselink-moxy-is-jaxb-provider-in.html)。 您可以使用以下錯誤跟蹤我們在此問題上的進展。 如果您是WebLogic客戶,請輸入一個錯誤,以便您可以接收適當的補丁程序。
Java模型
package forum13646211;
import javax.xml.bind.annotation.XmlElement;
public class Root {
private int[] testArrayInt;
@XmlElement(type=Integer.class)
public int [] getTestArrayInt () {
return testArrayInt;
}
public void setTestArrayInt(int[] array) {
this.testArrayInt = array;
}
}
模式(由JAXB RI生成)
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<xs:schema version="1.0" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:complexType name="root">
<xs:sequence>
<xs:element name="testArrayInt" type="xs:int" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
</xs:schema>
模式(由EclipseLink JAXB(MOXy)生成)
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:complexType name="root">
<xsd:sequence>
<xsd:element name="testArrayInt" type="xsd:int" minOccurs="0"/>
</xsd:sequence>
</xsd:complexType>
</xsd:schema>
模式生成代碼
package forum13646211;
import java.io.IOException;
import javax.xml.bind.*;
import javax.xml.transform.Result;
import javax.xml.transform.stream.StreamResult;
public class Demo {
public static void main(String[] args) throws Exception {
JAXBContext jc = JAXBContext.newInstance(Root.class);
jc.generateSchema(new SchemaOutputResolver() {
@Override
public Result createOutput(String namespaceUri,
String suggestedFileName) throws IOException {
StreamResult result = new StreamResult(System.out);
result.setSystemId(suggestedFileName);
return result;
}
});
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.