2012-05-04 13 views
0

私はJava/Eclipse/SpringでWebサービスを作成しています。私は、Webサービス(リクエスト、レスポンスなど)のためのJavaクラス用の構造を持つXSDファイルを作成しています。 私は、XSDファイルを使って "Generate Jaxb Classes"というオプションを使って、Javaクラスを作成しました。 int、string、longなどのデータ型では問題なく動作しますが、プロパティがObjectのArrayListである場合、生成されるJavaクラスにはそのプロパティの「SET」メソッドがありません。 「GET」メソッドしかありません。XSDファイルでオブジェクトのArrayListをマッピングする

これは一例です:

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に別のタグを追加する必要はありますか?

+0

誰も私を助けることはできませんか?道に迷いました –

答えて

0

は解決:

「のaddAll」と呼ばれる新しい方法は、(それが新しいものである場合、私は知らない)があります。 コレクションを取得してから、addAllを使用して別のコレクションを追加できます。

コード:

getPrizesAndCatalogsResponse.getPrizes().addAll(newPrizes); 
関連する問題