我已經從我的測試服務器返回一個JSON字符串,Android應用也越來越這很好,但是當我嘗試將其移動到使用MappingJackson2HttpMessageConverter它的一個字段是一個列表失敗的對象。無法識別領域
似乎無法找出原因,已經嘗試了許多註釋都沒有成功,誤差得到的是:
org.springframework.http.converter.HttpMessageNotReadableException: Could not read JSON: Unrecognized field "HourlySalesFigures" (class org.springframework.android.showcase.DayData),
not marked as ignorable (15 known properties: , "nextDate", "totalLoyalty", "previousDate", "totalCheque", "numberOfLoyaltySales", "totalGrand", "numberOfChequeSales", "hourlySalesFigures", "totalCard", "totalCash", "totalCharge" [truncated]])
返回的JSON數據:
我想{"HourlySalesFigures":[{"hour":0,"numberOfSales":0,"totalOfSales":0},{"hour":1,"numberOfSales":0,"totalOfSales":0},{"hour":2,"numberOfSales":0,"totalOfSales":0},{"hour":3,"numberOfSales":0,"totalOfSales":0},{"hour":4,"numberOfSales":0,"totalOfSales":0},{"hour":5,"numberOfSales":0,"totalOfSales":0},{"hour":6,"numberOfSales":0,"totalOfSales":0},{"hour":7,"numberOfSales":0,"totalOfSales":0},{"hour":8,"numberOfSales":0,"totalOfSales":0},{"hour":9,"numberOfSales":0,"totalOfSales":0},{"hour":10,"numberOfSales":4,"totalOfSales":548},{"hour":11,"numberOfSales":1,"totalOfSales":3},{"hour":12,"numberOfSales":7,"totalOfSales":209.5},{"hour":13,"numberOfSales":8,"totalOfSales":528.4},{"hour":14,"numberOfSales":13,"totalOfSales":1196.8},{"hour":15,"numberOfSales":9,"totalOfSales":1422.2},{"hour":16,"numberOfSales":12,"totalOfSales":321.5},{"hour":17,"numberOfSales":22,"totalOfSales":493.5},{"hour":18,"numberOfSales":21,"totalOfSales":740.5},{"hour":19,"numberOfSales":28,"totalOfSales":1180.5},{"hour":20,"numberOfSales":8,"totalOfSales":377.5},{"hour":21,"numberOfSales":9,"totalOfSales":859.8},{"hour":22,"numberOfSales":28,"totalOfSales":11193.8},{"hour":23,"numberOfSales":1,"totalOfSales":107}],"TargetDate":"2013/02/13","PreviousDate":"2013/02/12","NextDate":"2013/02/14","NumberOfCashSales":126,"TotalCash":8432.1,"NumberOfCardSales":23,"TotalCard":9775.9,"NumberOfChequeSales":0,"TotalCheque":0,"NumberOfLoyaltySales":0,"TotalLoyalty":0,"NumberOfChargeSales":22,"TotalCharge":974.0,"TotalGrand":19182.0}
Java對象(請注意我爲了簡潔而省略了吸氣劑和吸附劑)
DayData class
@Root
public class DayData {
@ElementList(name="HourlySalesFigures", inline=true)
protected List<HourSalesItem> hourlySalesFigures;
@Element(name="TargetDate")
protected String targetDate;
@Element(name="PreviousDate")
protected String previousDate;
@Element(name="NextDate")
protected String nextDate;
@Element(name="NumberOfCashSales")
protected int numberOfCashSales;
@Element(name="TotalCash")
protected double totalCash;
@Element(name="NumberOfCardSales")
protected int numberOfCardSales;
@Element(name="TotalCard")
protected double totalCard;
@Element(name="NumberOfChequeSales")
protected int numberOfChequeSales;
@Element(name="TotalCheque")
protected double totalCheque;
@Element(name="NumberOfLoyaltySales")
protected int numberOfLoyaltySales;
@Element(name="TotalLoyalty")
protected double totalLoyalty;
@Element(name="NumberOfChargeSales")
protected int numberOfChargeSales;
@Element(name="TotalCharge")
protected double totalCharge;
@Element(name="TotalGrand")
protected double totalGrand;
public DayData(List<HourSalesItem> HourlySalesFigures, String targetDate, String previousDate, String nextDate, int numberOfCashSales, double totalCash, int numberOfCardSales, double totalCard, int numberOfChequeSales, double totalCheque, int numberOfLoyaltySales, double totalLoyalty, int numberOfChargeSales, double totalCharge, double totalGrand) {
this.hourlySalesFigures = HourlySalesFigures;
this.targetDate = targetDate;
this.previousDate = previousDate;
this.nextDate = nextDate;
this.numberOfCashSales = numberOfCashSales;
this.totalCash = totalCash;
this.numberOfCardSales = numberOfCardSales;
this.totalCard = totalCard;
this.numberOfChequeSales = numberOfChequeSales;
this.totalCheque = totalCheque;
this.numberOfLoyaltySales = numberOfLoyaltySales;
this.totalLoyalty = totalLoyalty;
this.numberOfChargeSales = numberOfChargeSales;
this.totalCharge = totalCharge;
this.totalGrand = totalGrand;
}
public DayData()
{
}
}
HourSalesItem類
@Root
public class HourSalesItem{
@Element
private int hour;
@Element
private int numberOfSales;
@Element
private double totalOfSales;
public HourSalesItem(int hour, int numberOfSales, double totalOfSales) {
this.hour = hour;
this.numberOfSales = numberOfSales;
this.totalOfSales = totalOfSales;
}
public HourSalesItem(){
}
}
嘗試重命名你的變量。作爲HourlySalesFigures,TargetDate等 –
想到了這一點,因此@Element(name =「TotalGrand」)註釋。但無論如何重命名變量並重試,同樣的錯誤。 –
DayData構造函數沒有在CamelCase中有HourlySalesFigures參數,也許這可能是問題?我不確定,只是猜測。 –