将jira json字符串转换为java对象

时间:2013-07-18 13:20:32

标签: java json jira

如何将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可以执行此操作?

2 个答案:

答案 0 :(得分:2)

如果你的类有一个类似你所展示的json的结构,你可以使用gson库将它绑定到类。

答案 1 :(得分:1)

我通过另一个第三方库处理此问题,您可以下载此代码。并编辑为您的方案。

您只应在此Java类中编辑SimpleConfigurationProvider。 您必须指定您的privateKey,AccessToken和baseUrl。然后通过jiraClient身份验证,您可以接收项目并通过以下代码块进行颁发

因此,您可以将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());
                 ///.....
            }
        }
    }
}