【发布时间】:2016-05-02 05:12:08
【问题描述】:
我有以下 JSON 响应,想转换成 Java,然后将数据保存到数据库。
我查看了各种工具,但无法找到合适的解决方案。
我做错了什么,但无法理解差距在哪里。
下面是我的 JSON:
{
"release-1.0": [{
"id": 55,
"resourceId": "126",
"allGraphs": null,
"isChecked": true
}, {
"id": 56,
"resourceId": "125",
"allGraphs": null,
"isChecked": true
}, {
"id": 58,
"resourceId": "140",
"allGraphs": null,
"isChecked": true
}]
}
这是我到上述 JSON 的 Java 类映射。
@DatabaseTable(tableName = "test_group")
public class TestGroup {
private List<TestGroup> testGroup;
public TestGroup() {
// ORMLite needs a no-arg constructor
}
@DatabaseField
private List<String> test_group_id;
@DatabaseField
private String id;
@DatabaseField
private String test_details;
@DatabaseField
private String graph_id;
public void setTestGroupID(List<String> testGroupId) {
this.test_group_id = testGroupId;
}
public void setId(String id) {
this.id = id;
}
public void testDetails(String testDetails) {
this.test_details = testDetails;
}
public void setGraphId(String allGraphs) {
this.graph_id = allGraphs;
}
public List<TestGroup> getAllGraphs() {
return testGroup;
}
}
我用过Jackson,但出现如下错误:
com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException: Unrecognized field "release-1.0" (class org.example.model.TestGroup), not marked as ignorable (4 known properties: "testGroupID", "graphId", "id", "allGraphs"])
at [Source: {"release-1.0":[{"id":55,"resourceId":"126","allGraphs":null,"isChecked":true},{"id":56,"resourceId":"125","allGraphs":null,"isChecked":true},{"id":58,"resourceId":"140","allGraphs":null,"isChecked":true}]}; line: 1, column: 17]
请帮忙。
提前致谢。
【问题讨论】:
标签: java json jackson gson dao