如何将JSON转换为POJO

时间:2013-10-15 17:39:47

标签: json jersey jersey-client

无论如何要从JSON字符串创建Java POJO模板?我正在使用Jersey

{
  "reviewData" : [ {
    "projectKey" : "CR-FOO",
    "name" : "Example review.",
    "description" : "Description or statement of objectives for this example review.",
    "author" : {
      "userName" : "joe",
      "displayName" : "Joe Krustofski",
      "avatarUrl" : "http://foo.com/avatar"
    },
    "moderator" : {
      "userName" : "scott",
      "displayName" : "Scott the Moderator",
      "avatarUrl" : "http://foo.com/avatar"
    },
    "creator" : {
      "userName" : "joe",
      "displayName" : "Joe Krustofski",
      "avatarUrl" : "http://foo.com/avatar"
    },
    "permaId" : {
      "id" : "CR-FOO-21"
    },
    "permaIdHistory" : [ "CR-FOO-21" ],
    "type" : "REVIEW",
    "allowReviewersToJoin" : true,
    "metricsVersion" : 4,
    "createDate" : "2013-10-08T15:46:11.022+0200",
    "dueDate" : "2013-10-09T15:46:11.022+0200",
    "jiraIssueKey" : "FOO-6754"
  }, {
    "projectKey" : "CR-FOO",
    "name" : "Example review.",
    "description" : "Description or statement of objectives for this example review.",
    "author" : {
      "userName" : "joe",
      "displayName" : "Joe Krustofski",
      "avatarUrl" : "http://foo.com/avatar"
    },
    "moderator" : {
      "userName" : "scott",
      "displayName" : "Scott the Moderator",
      "avatarUrl" : "http://foo.com/avatar"
    },
    "creator" : {
      "userName" : "joe",
      "displayName" : "Joe Krustofski",
      "avatarUrl" : "http://foo.com/avatar"
    },
    "permaId" : {
      "id" : "CR-FOO-21"
    },
    "permaIdHistory" : [ "CR-FOO-21" ],
    "type" : "REVIEW",
    "allowReviewersToJoin" : true,
    "metricsVersion" : 4,
    "createDate" : "2013-10-08T15:46:11.022+0200",
    "dueDate" : "2013-10-09T15:46:11.022+0200",
    "jiraIssueKey" : "FOO-6754"
  } ]
}

1 个答案:

答案 0 :(得分:5)

我找到的最佳解决方案是http://www.jsonschema2pojo.org/

它支持Jackson和Maven以及在线工具。