I m working with Java/Eclipse/Spring to create a Web Services. I m writing a XSD file with the structure for the Java Classes for the Web Services (Request, Response, etc). I used the option "Generate Jaxb Classes", over the XSD file, to create the Java classes. It is working fine for data types like int, string, long, etc, but, when my property is an ArrayList of Objects, the Java class generated doesn t have the "SET" method of the property. It only have the "GET" method.
例如:
XSD 档案:
<element name="GetPrizesAndCatalogsResponse">
<complexType>
<sequence>
<element name="answerCode" type="int" />
<element name="prizes" type="tns:SW_Prize" maxOccurs="unbounded"></element>
<element name="prizesCatalog" type="tns:SW_Catalog" maxOccurs="unbounded"></element>
<element name="pagination" type="tns:SW_Pagination"></element>
</sequence>
</complexType>
</element>
Java类:
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "", propOrder = {
"answerCode",
"prizes",
"prizesCatalog",
"pagination"
})
@XmlRootElement(name = "GetPrizesAndCatalogsResponse")
public class GetPrizesAndCatalogsResponse {
protected int answerCode;
@XmlElement(required = true)
protected List<SWPrize> prizes;
@XmlElement(required = true)
protected List<SWCatalog> prizesCatalog;
@XmlElement(required = true)
protected SWPagination pagination;
/**
* Obtiene el valor de la propiedad answerCode.
*
*/
public int getAnswerCode() {
return answerCode;
}
/**
* Define el valor de la propiedad answerCode.
*
*/
public void setAnswerCode(int value) {
this.answerCode = value;
}
/**
* Gets the value of the prizes property.
*
* <p>
* This accessor method returns a reference to the live list,
* not a snapshot. Therefore any modification you make to the
* returned list will be present inside the JAXB object.
* This is why there is not a <CODE>set</CODE> method for the prizes property.
*
* <p>
* For example, to add a new item, do as follows:
* <pre>
* getPrizes().add(newItem);
* </pre>
*
*
* <p>
* Objects of the following type(s) are allowed in the list
* {@link SWPrize }
*
*
*/
public List<SWPrize> getPrizes() {
if (prizes == null) {
prizes = new ArrayList<SWPrize>();
}
return this.prizes;
}
/**
* Gets the value of the prizesCatalog property.
*
* <p>
* This accessor method returns a reference to the live list,
* not a snapshot. Therefore any modification you make to the
* returned list will be present inside the JAXB object.
* This is why there is not a <CODE>set</CODE> method for the prizesCatalog property.
*
* <p>
* For example, to add a new item, do as follows:
* <pre>
* getPrizesCatalog().add(newItem);
* </pre>
*
*
* <p>
* Objects of the following type(s) are allowed in the list
* {@link SWCatalog }
*
*
*/
public List<SWCatalog> getPrizesCatalog() {
if (prizesCatalog == null) {
prizesCatalog = new ArrayList<SWCatalog>();
}
return this.prizesCatalog;
}
/**
* Obtiene el valor de la propiedad pagination.
*
* @return
* possible object is
* {@link SWPagination }
*
*/
public SWPagination getPagination() {
return pagination;
}
/**
* Define el valor de la propiedad pagination.
*
* @param value
* allowed object is
* {@link SWPagination }
*
*/
public void setPagination(SWPagination value) {
this.pagination = value;
}
}
我对XSD档案的定义是否正确? 是否需要在XML上添加另一个标签?