Java - 将动态JSON映射到DTO

时间:2017-08-21 08:00:07

标签: java spring-mvc dto

我有问题将json数据映射到带有后续有效负载的DTO&#p>

"wigData": {
        "wig": {
            "0": {
                "parentWig": "",
                "wigName": "testing wig 1",
                "wigStart": "01/08/2017",
                "wigFromx": "1",
                "wigToy": "123",
                "wigEnd": "31/08/2017",
                "wigAchievementType": "number"
            },
            "1": {
                "parentWig": "",
                "wigName": "testing wig 2",
                "wigStart": "01/08/2017",
                "wigFromx": "1",
                "wigToy": "123",
                "wigEnd": "31/08/2017",
                "wigAchievementType": "number"
            }
        }
    }

DTO未能映射wig的有效负载,因为它是从jquery json serializable序列化数据

我为此有效负载创建了DTO,

class WigData {
    private Wigs wigs;
// setter getter
}

class Wigs {
    private List<Wig> index;
// setter getter
}

class Wig {
    private String parentWig;
    private String wigName;
    private Date wigStart;
    private Date wigFromx;
    private BigDecimal wigToy;
    private String wigAchievementType;
// setter getter
}

这是此DTO的输出

wigData: {
  wigs: null
}

但没有运气,有人可以帮忙解决这个问题吗?

因为现在无法更改有效负载

1 个答案:

答案 0 :(得分:2)

在JSON数组上查看更多内容。

尝试使用以下内容:

"wigData": {
    "wig": [{
            "parentWig": "",
            "wigName": "testing wig 1",
            "wigStart": "01/08/2017",
            "wigFromx": "1",
            "wigToy": "123",
            "wigEnd": "31/08/2017",
            "wigAchievementType": "number"
        }, {
            "parentWig": "",
            "wigName": "testing wig 2",
            "wigStart": "01/08/2017",
            "wigFromx": "1",
            "wigToy": "123",
            "wigEnd": "31/08/2017",
            "wigAchievementType": "number"
        }
    ]
}

class WigData {
    private List<Wig> wig;
    // setter getter
}

class Wig {
    private String parentWig;
    private String wigName;
    private Date wigStart;
    private Date wigFromx;
    private BigDecimal wigToy;
    private String wigAchievementType;
// setter getter
}