我有一个用例,我想返回一个JSON,如下所示:
"chartData": [
{
"y1": 1889181,
"y2": 1359730,
"y3": 24,
"x": 0
}
]
我正在使用以下代码:
public class Chart {
private DataPoint[] fChartData;
@JsonProperty("chartData")
public DataPoint[] getChartData() { return fChartData; }
public void addChartData(List<DataPoint> chartData) {
DataPoint[] array = chartData.toArray(new DataPoint[chartData.size()]);
fChartData = ArrayUtils.addAll(fChartData, array);
}
}
public class DataPoint {
private HashMap<String, Double> fDataPointValues = new HashMap<>();
public DataPoint() {
// constructor
}
public HashMap<String, Double> getSingleDataPointValues() { return fDataPointValues; }
public void addValues(String name, double value) {
fDataPointValues.put(name, value);
}
}
但是,此代码返回的JSON如下:
"chartData": [
{
"singleDataPointValues": {
"y1": 1889181,
"y2": 1359730,
"y3": 24,
"x": 0
}
}
]
我在这里做错了什么?以及如何返回JSON作为第一个示例?