В настоящее время я использую REST API, который был создан не очень хорошо.JSON-объект quarterly
должен иметь список или массив объектов внутри, но вместо этого он просто имеет объекты, которые можно адресовать по дате («2018-09-29» и т. Д.).
Я использую Retrofit2, чтобы вытянуть этот JSON в классы POJO, однако моя текущая реализация не работает, поскольку она ожидает список JSON.Я был бы признателен, если бы кто-нибудь мог помочь мне понять, как изменить мой java, чтобы он сохранял все квартальные объекты в списке java.
В настоящее время список в классе CashFlowRecordList
равен null
- т.е.он не заполняется при вызове REST.
Мой вопрос почти такой же, как: Преобразование структуры json в массив с помощью Retrofit .Но он все еще не отвечает, как это сделать с помощью Retrofit.
JSON:
Cash_Flow": {
"currency_symbol": "USD",
"quarterly": {
"2018-09-29": {
"date": "2018-09-29",
"filing_date": "2018-11-05",
"investments": "552000000.00",
"changeToLiabilities": "20373000000.00",
"totalCashflowsFromInvestingActivities": "-3001000000.00",
"netBorrowings": "-27000000.00",
"totalCashFromFinancingActivities": "-22580000000.00",
"changeToOperatingActivities": "-12423000000.00",
"netIncome": "14125000000.00",
"changeInCash": "-6058000000.00",
},
"2018-06-30": {
"date": "2018-06-30",
"filing_date": "2018-08-01",
"investments": "7916000000.00",
"changeToLiabilities": "1500000000.00",
"totalCashflowsFromInvestingActivities": "3947000000.00",
"netBorrowings": "-6011000000.00",
"totalCashFromFinancingActivities": "-31523000000.00",
"changeToOperatingActivities": "-5340000000.00",
"netIncome": "11519000000.00",
"changeInCash": "-13088000000.00",
},
...
}
}
JAVA:
CashFlow
public class CashFlow {
public CashFlow(CashFlowRecordList quarterly, CashFlowRecordList yearly) {
this.quarterly = quarterly;
this.yearly = yearly;
//
}
public CashFlow() {
// TODO Auto-generated constructor stub
}
@SerializedName("quarterly")
@Expose private CashFlowRecordList quarterly;
@SerializedName("yearly")
@Expose private CashFlowRecordList yearly;
public CashFlowRecordList getQuarterly() {
return quarterly;
}
public void setQuarterly(CashFlowRecordList quarterly) {
this.quarterly = quarterly;
}
public CashFlowRecordList getYearly() {
return yearly;
}
public void setYearly(CashFlowRecordList yearly) {
this.yearly = yearly;
}
}
CashFlowRecordList
public class CashFlowRecordList {
@Expose public CashFlowRecord cashFlowRecord[];
public CashFlowRecordList() {
// TODO Auto-generated constructor stub
}
public CashFlowRecordList(CashFlowRecord[] cashFlowRecord){
this.cashFlowRecord = cashFlowRecord;
}
public CashFlowRecord[] getCashFlowRecord() {
return cashFlowRecord;
}
public void setCashFlowRecord(CashFlowRecord[] cashFlowRecord) {
this.cashFlowRecord = cashFlowRecord;
}
}
CashFlowRecord
public class CashFlowRecord {
@SerializedName("date")
@Expose
private String date;
@SerializedName("investments")
@Expose
private String investments;
@SerializedName("changeToLiabilities")
@Expose
private String changeToLiabilities;
@SerializedName("totalCashflowsFromInvestingActivities")
@Expose
private String totalCashflowsFromInvestingActivities;
@SerializedName("netBorrowings")
@Expose
private String netBorrowings;
@SerializedName("totalCashFromFinancingActivities")
@Expose
private String totalCashFromFinancingActivities;
@SerializedName("changeToOperatingActivities")
@Expose
private String changeToOperatingActivities;
@SerializedName("netIncome")
@Expose
private String netIncome;
@SerializedName("changeInCash")
@Expose
private String changeInCash;
@SerializedName("totalCashFromOperatingActivities")
@Expose
private String totalCashFromOperatingActivities;
@SerializedName("depreciation")
@Expose
private String depreciation;
@SerializedName("otherCashflowsFromInvestingActivities")
@Expose
private String otherCashflowsFromInvestingActivities;
@SerializedName("dividendsPaid")
@Expose
private String dividendsPaid;
@SerializedName("changeToInventory")
@Expose
private String changeToInventory;
@SerializedName("changeToAccountReceivables")
@Expose
private String changeToAccountReceivables;
@SerializedName("salePurchaseOfStock")
@Expose
private String salePurchaseOfStock;
@SerializedName("otherCashflowsFromFinancingActivities")
@Expose
private String otherCashflowsFromFinancingActivities;
@SerializedName("changeToNetincome")
@Expose
private String changeToNetincome;
@SerializedName("capitalExpenditures")
@Expose
private String capitalExpenditures;
public String getDate() {
return date;
}
public void setDate(String date) {
this.date = date;
}
public String getInvestments() {
return investments;
}
public void setInvestments(String investments) {
this.investments = investments;
}
public String getChangeToLiabilities() {
return changeToLiabilities;
}
public void setChangeToLiabilities(String changeToLiabilities) {
this.changeToLiabilities = changeToLiabilities;
}
public String getTotalCashflowsFromInvestingActivities() {
return totalCashflowsFromInvestingActivities;
}
public void setTotalCashflowsFromInvestingActivities(String totalCashflowsFromInvestingActivities) {
this.totalCashflowsFromInvestingActivities = totalCashflowsFromInvestingActivities;
}
public String getNetBorrowings() {
return netBorrowings;
}
public void setNetBorrowings(String netBorrowings) {
this.netBorrowings = netBorrowings;
}
public String getTotalCashFromFinancingActivities() {
return totalCashFromFinancingActivities;
}
public void setTotalCashFromFinancingActivities(String totalCashFromFinancingActivities) {
this.totalCashFromFinancingActivities = totalCashFromFinancingActivities;
}
public String getChangeToOperatingActivities() {
return changeToOperatingActivities;
}
public void setChangeToOperatingActivities(String changeToOperatingActivities) {
this.changeToOperatingActivities = changeToOperatingActivities;
}
public String getNetIncome() {
return netIncome;
}
public void setNetIncome(String netIncome) {
this.netIncome = netIncome;
}
public String getChangeInCash() {
return changeInCash;
}
public void setChangeInCash(String changeInCash) {
this.changeInCash = changeInCash;
}
public String getTotalCashFromOperatingActivities() {
return totalCashFromOperatingActivities;
}
public void setTotalCashFromOperatingActivities(String totalCashFromOperatingActivities) {
this.totalCashFromOperatingActivities = totalCashFromOperatingActivities;
}
public String getDepreciation() {
return depreciation;
}
public void setDepreciation(String depreciation) {
this.depreciation = depreciation;
}
public String getOtherCashflowsFromInvestingActivities() {
return otherCashflowsFromInvestingActivities;
}
public void setOtherCashflowsFromInvestingActivities(String otherCashflowsFromInvestingActivities) {
this.otherCashflowsFromInvestingActivities = otherCashflowsFromInvestingActivities;
}
public String getDividendsPaid() {
return dividendsPaid;
}
public void setDividendsPaid(String dividendsPaid) {
this.dividendsPaid = dividendsPaid;
}
public String getChangeToInventory() {
return changeToInventory;
}
public void setChangeToInventory(String changeToInventory) {
this.changeToInventory = changeToInventory;
}
public String getChangeToAccountReceivables() {
return changeToAccountReceivables;
}
public void setChangeToAccountReceivables(String changeToAccountReceivables) {
this.changeToAccountReceivables = changeToAccountReceivables;
}
public String getSalePurchaseOfStock() {
return salePurchaseOfStock;
}
public void setSalePurchaseOfStock(String salePurchaseOfStock) {
this.salePurchaseOfStock = salePurchaseOfStock;
}
public String getOtherCashflowsFromFinancingActivities() {
return otherCashflowsFromFinancingActivities;
}
public void setOtherCashflowsFromFinancingActivities(String otherCashflowsFromFinancingActivities) {
this.otherCashflowsFromFinancingActivities = otherCashflowsFromFinancingActivities;
}
public String getChangeToNetincome() {
return changeToNetincome;
}
public void setChangeToNetincome(String changeToNetincome) {
this.changeToNetincome = changeToNetincome;
}
public String getCapitalExpenditures() {
return capitalExpenditures;
}
public void setCapitalExpenditures(String capitalExpenditures) {
this.capitalExpenditures = capitalExpenditures;
}
}