2016-05-17 1 views
0

dbからデータを取得して、個々のタグの応答に表示しようとしていますが、期待される出力を得ることができません。 implのために私が使用しているコードを見つけてください。私が間違っていることを見つけることができません。DBからデータを取得してxsd要素タグに設定する

私のImplコード -

AccountLoyaltyDetail loyaltyobj1 = new AccountLoyaltyDetail(); 
     List<AccountLoyaltyDetail> loyaltyobj = new ArrayList<AccountLoyaltyDetail>(); 
     AccountLoyaltyDetail loyaltyobjtemp = new AccountLoyaltyDetail(); 
    for (final Object[] records : resultList) { 
         String Journey_Id = assignStringRecordValue(records[2]); 
         // SET OBJECT VALUES 
         loyaltyobjtemp.setJourneys(Journey_Id); 
         loyaltyobj.add(loyaltyobjtemp); 
        } 

        loyaltyobj.add(loyaltyobj1); 

私のPOJO、エレメント

// This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, v2.1.7-1.2.0.0_2-1-7-fcs 
// See <a href="http://java.sun.com/xml/jaxb">http://java.sun.com/xml/jaxb</a> 
// Any modifications to this file will be lost upon recompilation of the source schema. 
// Generated on: 2016.05.18 at 12:04:56 PM IST 
// 


package com.fedex.marketing.loyaltyws.objects; 

import java.util.ArrayList; 
import java.util.List; 

import javax.xml.bind.annotation.XmlAccessType; 
import javax.xml.bind.annotation.XmlAccessorType; 
import javax.xml.bind.annotation.XmlElement; 
import javax.xml.bind.annotation.XmlType; 


/** 
* <p>Java class for AccountLoyaltyDetail complex type. 
* 
* <p>The following schema fragment specifies the expected content contained within this class. 
* 
* <pre> 
* &lt;complexType name="AccountLoyaltyDetail"> 
* &lt;complexContent> 
*  &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType"> 
*  &lt;sequence> 
*   &lt;element name="OperatingCompany" type="{http://fedex.com/ws/loyalty/v1}OperatingCompanyType" minOccurs="0"/> 
*   &lt;element name="Journeys" type="{http://fedex.com/ws/loyalty/v1}LoyaltyJourneyIdentifier"/> 
*   &lt;element name="Segments" type="{http://fedex.com/ws/loyalty/v1}LoyaltySegmentIdentifier"/> 
*  &lt;/sequence> 
*  &lt;/restriction> 
* &lt;/complexContent> 
* &lt;/complexType> 
* </pre> 
* 
* 
*/ 
@XmlAccessorType(XmlAccessType.FIELD) 
@XmlType(name = "AccountLoyaltyDetail", propOrder = { 
    "operatingCompany", 
    "journeys", 
    "segments" 
}) 
public class AccountLoyaltyDetail { 

    @XmlElement(name = "OperatingCompany") 
    protected OperatingCompanyType operatingCompany; 
    @XmlElement(name = "Journeys", required = true) 
    protected List<LoyaltyJourneyIdentifier> journeys = new ArrayList<LoyaltyJourneyIdentifier>(); 
    @XmlElement(name = "Segments", required = true) 
    protected List<LoyaltySegmentIdentifier> segments = new ArrayList<LoyaltySegmentIdentifier>(); 

    /** 
    * Gets the value of the operatingCompany property. 
    * 
    * @return 
    *  possible object is 
    *  {@link OperatingCompanyType } 
    *  
    */ 
    public OperatingCompanyType getOperatingCompany() { 
     return operatingCompany; 
    } 

    public List<LoyaltyJourneyIdentifier> getJourneys() { 
     return journeys; 
    } 

    public void setJourneys(List<LoyaltyJourneyIdentifier> journeys) { 
     this.journeys = journeys; 
    } 

    public List<LoyaltySegmentIdentifier> getSegments() { 
     return segments; 
    } 

    public void setSegments(List<LoyaltySegmentIdentifier> segments) { 
     this.segments = segments; 
    } 

    /** 
    * Sets the value of the operatingCompany property. 
    * 
    * @param value 
    *  allowed object is 
    *  {@link OperatingCompanyType } 
    *  
    */ 
    public void setOperatingCompany(OperatingCompanyType value) { 
     this.operatingCompany = value; 
    } 



} 

実際の出力 -

 <LoyaltyDetails> 
      <Journeys>FIRM_EMP_HERE_QTY|99</Journeys> 
     </LoyaltyDetails> 
     <LoyaltyDetails> 
      <Journeys>FIRM_EMP_HERE_QTY|99</Journeys> 
     </LoyaltyDetails> 

予想される出力 - :

<xs:complexType name="AccountLoyaltyDetail"> 
      <xs:sequence> 
       <xs:element name="OperatingCompany" type="ns:OperatingCompanyType" 
        minOccurs="0" /> 
       <xs:element name="Journeys" type="ns:LoyaltyJourneyIdentifier>" /> 
       <xs:element name="Segments" type="ns:LoyaltySegmentIdentifier" /> 
      </xs:sequence> 
     </xs:complexType> 

    <xs:complexType name="LoyaltyJourneyIdentifier"> 
      <xs:sequence> 
        <xs:element name="JourneyIdentifierId" type="xs:string" 
         minOccurs="0"> 
         <xs:annotation> 
           <xs:documentation>Free form text to be echoed back in the reply. 
            Used to match requests and replies.</xs:documentation> 
         </xs:annotation> 
        </xs:element> 
      </xs:sequence> 

</xs:complexType> 

答えて

0
You need to create a List<AccountLoyaltyDetail> object within AccountLoyaltyDetail and annotate it as @XmlElement. This will create an infinite loop. It is not possible. 



**POJOs:** 
@XmlRootElement 
class AccountLoyaltyDetail { 
    @XmlElement(name="journeys") 
    private List<LoyaltyJourneyIdentifier> journeyList = new ArrayList<>(); 
    getters and setters... 
} 

@XmlRootElement 
class LoyaltyJourneyIdentifier { 
    @XmlElement 
    private String journeyName; 
    getters and setters.... 
} 

**IMPL:** 
AccountLoyaltyDetail loyaltytemp = new AccountLoyaltyDetail(); 
for (final Object[] records : resultList) {     

        LoyaltyJourneyIdentifier journey = new LoyaltyJourneyIdentifier(); 

        String Journey_Id = assignStringRecordValue(records[2]); 
        // SET OBJECT VALUES 
        journey.setJourney(Journey_Id);  
        loyaltytemp.setJourneyName(journey); 

       } 
marshallerObj.marshal(loyaltytemp, ....) 
+0

がどのように私はここで直接のArrayList型を使用し.Canを一覧表示するように変更します

<LoyaltyDetails> <LoyaltyDetails> <Journeys>FIRM_EMP_HERE_QTY|99</Journeys> <Journeys>FIRM_EMP_HERE_QTY|99</Journeys> </LoyaltyDetails> 

XSD? – themaster

+0

ありがとう。この場合、私のxsdは何ですか? – themaster

+0

<?xml version = "1.0" encoding = "UTF-8"?> SundarPichai

関連する問題