1

これは私のジャージサービスが返すクラスです:

@XmlRootElement(name="chart-data")
public class ChartDataDto {
private List<Series> series = new ArrayList<>();

    public ChartDataDto()
    {

    }

    public void putSeries(String name, Integer... series)
    {
        this.series.add(new Series(name, series));
    }

    @XmlElement(name="series")
    public List<Series> getSeries()
    {
        return this.series;
    }

    @XmlRootElement(name="series")
    static class Series
    {
        @XmlElement(name="name")
        public String name;
        @XmlElement(name="values")
        public List<Integer> series;

        public Series()
        {

        }

        public Series(String name, Integer... series)
        {
            this.name = name;

            this.series = Arrays.asList(series);
        }
    }
}

返されるJSON文字列は次のとおりです。

{"series":[
    {
        "name":"Series 1",
        "values":["1","2","2","3","3","4","4","5","5","6","6","7","7"]
    },{
        "name":"Series 2",
        "values":["7","7","6","6","5","5","4","4","3","3","2","2","1"]
    }
]}

しかし、正しいJSON文字列は次のようになるはずです。

{"series":[
    {
        "name":"Series 1",
        "values":[1,2,2,3,3,4,4,5,5,6,6,7,7]
    },{
        "name":"Series 2",
        "values":[7,7,6,6,5,5,4,4,3,3,2,2,1]
    }
]}

何が問題なのですか?整数リストのタイプが間違っていますか?間違った注釈?

4

1 に答える 1

0

を使用するJacksonGson、コードが適切に機能します。

于 2012-09-19T10:30:24.043 に答える