1

如何将 jira json 字符串转换为 java 对象我想获取问题详细信息

{
  "expand": "schema,names",
  "startAt": 0,
  "maxResults": 50,
  "total": 1,
  "issues": [
    {
      "expand": "editmeta,renderedFields,transitions,changelog,operations",
      "id": "10000",
      "self": "http://jira.com/rest/api/2/issue/10000",
      "key": "APPANLYTIX-1",
      "fields": {},
        "issuetype": {},
        "votes": {},
        "resolution": null,
        "fixVersions": [{}],
        "resolutiondate": null,
        "timespent": null,
        "reporter": {
          "avatarUrls": {},
          "displayName": "yyyy Dev",
          "active": true
        },
        "subtasks": [],
        "status": {},
        "labels": [],
        "workratio": 0,
        "assignee": {
          "avatarUrls": {},
          "displayName": "",
          "active": true
        },
        "project": {
          "name": "",
          "avatarUrls": { }
        },
        "versions": [{}],
        "environment": "windows",
        "timeestimate": 28800,
        "aggregateprogress": {},
        "lastViewed": "2013-07-18T04:39:52.596+0000",
        "components": [ ],
        "timeoriginalestimate": 28800,
        "aggregatetimespent": null
    }
  ]
}

我推荐的大多数示例都使用 java bean 来设置变量,是否有任何 API 可以做到这一点?

4

2 回答 2

2

如果您的类具有像您展示的 json 这样的结构,您可以使用gson库将其绑定到类。

于 2013-07-18T22:54:17.040 回答
1

我处理这个问题另一个第三方库,你可以下载这个代码。并根据您的情况进行编辑。

您应该只编辑 SimpleConfigurationProvider 这个 java 类。您必须指定您的 privateKey、AccessToken 和 baseUrl。然后 jiraClient Authentication 你可以接收项目和问题,这要归功于代码块

因此,您可以将 java 类对象转换为 ArrayList 和 JiraProject[]

https://github.com/symphonyoss/bot-jira

    public static void main(String[] args) {
    // TODO Auto-generated method stub
    JiraOauthClient jiraClient = new JiraOauthClient(new SimpleConfigurationProvider());
    JiraProject[] projects = jiraClient.getAllProjects();

    for (JiraProject project : projects) {
        if (project.getKey().equals("UOCM")) {
            ArrayList<JiraIssue> issues = jiraClient.getIssuesForProject(project);

            for (JiraIssue issue : issues) {
                System.out.println(issue.getId());
                 ///.....
            }
        }
    }
}
于 2019-06-14T14:34:19.907 回答