1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package com.atlassian.jira.rest.client.internal.json;
18
19 import com.atlassian.jira.rest.client.domain.BasicComponent;
20 import com.atlassian.jira.rest.client.domain.BasicUser;
21 import com.atlassian.jira.rest.client.domain.Project;
22 import com.atlassian.jira.rest.client.domain.Version;
23 import org.codehaus.jettison.json.JSONException;
24 import org.codehaus.jettison.json.JSONObject;
25
26 import java.net.URI;
27 import java.net.URISyntaxException;
28 import java.util.Collection;
29
30 public class ProjectJsonParser implements JsonParser<Project> {
31 private final VersionJsonParser versionJsonParser = new VersionJsonParser();
32 private final BasicComponentJsonParser componentJsonParser = new BasicComponentJsonParser();
33 @Override
34 public Project parse(JSONObject json) throws JSONException {
35 URI self = JsonParseUtil.getSelfUri(json);
36 final BasicUser lead = JsonParseUtil.parseBasicUser(json.getJSONObject("lead"));
37 final String key = json.getString("key");
38 final String urlStr = JsonParseUtil.getOptionalString(json, "url");
39 URI uri;
40 try {
41 uri = urlStr == null || "".equals(urlStr) ? null : new URI(urlStr);
42 } catch (URISyntaxException e) {
43 uri = null;
44 }
45 String description = JsonParseUtil.getOptionalString(json, "description");
46 if ("".equals(description)) {
47 description = null;
48 }
49 final Collection<Version> versions = JsonParseUtil.parseJsonArray(json.getJSONArray("versions"), versionJsonParser);
50 final Collection<BasicComponent> components = JsonParseUtil.parseJsonArray(json.getJSONArray("components"), componentJsonParser);
51 return new Project(self, key, description, lead, uri, versions, components);
52
53 }
54 }