我正在尝试从数据库中获取数据并在单个标记的响应中显示它。但是我无法获得预期的输出。请找到我用于impl的代码。无法找出我做错了什么。
我的Impl代码 -
BluetoothManager manager = (BluetoothManager) getSystemService(BLUETOOTH_SERVICE);
mBluetoothAdapter = manager.getAdapter();
mBluetoothLeAdvertiser = mBluetoothAdapter.getBluetoothLeAdvertiser();
// Settings here
mBluetoothLeAdvertiser.startAdvertising(settings, getAdvertiseData(), mAdvertiseCallback);
我的pojo元素 -
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);
实际输出 -
// 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>
* <complexType name="AccountLoyaltyDetail">
* <complexContent>
* <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
* <sequence>
* <element name="OperatingCompany" type="{http://fedex.com/ws/loyalty/v1}OperatingCompanyType" minOccurs="0"/>
* <element name="Journeys" type="{http://fedex.com/ws/loyalty/v1}LoyaltyJourneyIdentifier"/>
* <element name="Segments" type="{http://fedex.com/ws/loyalty/v1}LoyaltySegmentIdentifier"/>
* </sequence>
* </restriction>
* </complexContent>
* </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>
XSD
<LoyaltyDetails>
<LoyaltyDetails>
<Journeys>FIRM_EMP_HERE_QTY|99</Journeys>
<Journeys>FIRM_EMP_HERE_QTY|99</Journeys>
</LoyaltyDetails>
答案 0 :(得分: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, ....)