Java - 映射动态 JSON 到 DTO

Java - Mapping dynamic JSON to DTO

我无法将 json 数据映射到具有以下有效负载的 DTO

"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
}

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

因为现在无法更改负载

查看 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
}