因为项目对接了jira,jira api查询的数据太复杂且没有固定格式,所以写了一个简单的映射
// 原始数据
{
"expand": "projects",
"projects": [
{
"self": "http://10.50.10.100:30089/rest/api/2/project/10003",
"id": "10003",
"key": "GO",
"name": "GO",
"avatarUrls": {
"48x48": "http://10.50.10.100:30089/secure/projectavatar?pid=10003&avatarId=10606",
"24x24": "http://10.50.10.100:30089/secure/projectavatar?size=small&pid=10003&avatarId=10606",
"16x16": "http://10.50.10.100:30089/secure/projectavatar?size=xsmall&pid=10003&avatarId=10606",
"32x32": "http://10.50.10.100:30089/secure/projectavatar?size=medium&pid=10003&avatarId=10606"
},
"issuetypes": [
{
"self": "http://10.50.10.100:30089/rest/api/2/issuetype/10002",
"id": "10002",
"description": "需要完成的任务。",
"iconUrl": "http://10.50.10.100:30089/secure/viewavatar?size=xsmall&avatarId=10318&avatarType=issuetype",
"name": "任务",
"subtask": false
},
{
"self": "http://10.50.10.100:30089/rest/api/2/issuetype/10003",
"id": "10003",
"description": "事务的子任务。",
"iconUrl": "http://10.50.10.100:30089/secure/viewavatar?size=xsmall&avatarId=10316&avatarType=issuetype",
"name": "开发子任务",
"subtask": true
},
{
"self": "http://10.50.10.100:30089/rest/api/2/issuetype/10001",
"id": "10001",
"description": "由 Jira Software 创建——请勿编辑或删除。适用于一种用户故事的事务类型。",
"iconUrl": "http://10.50.10.100:30089/images/icons/issuetypes/story.svg",
"name": "故事",
"subtask": false
},
{
"self": "http://10.50.10.100:30089/rest/api/2/issuetype/10202",
"id": "10202",
"description": "For Go2Group SYNAPSE Test Case issue type",
"iconUrl": "http://10.50.10.100:30089/download/resources/com.go2group.jira.plugin.synapse/synapse/images/icon-testcase.png",
"name": "测试用例",
"subtask": false
},
{
"self": "http://10.50.10.100:30089/rest/api/2/issuetype/10203",
"id": "10203",
"description": "For Go2Group SYNAPSE Test Plan issue type",
"iconUrl": "http://10.50.10.100:30089/download/resources/com.go2group.jira.plugin.synapse/synapse/images/icon-testplan.png",
"name": "测试计划",
"subtask": false
},
{
"self": "http://10.50.10.100:30089/rest/api/2/issuetype/10204",
"id": "10204",
"description": "For Go2Group SYNAPSE Bug issue type",
"iconUrl": "http://10.50.10.100:30089/download/resources/com.go2group.jira.plugin.synapse/synapse/images/icon-bug.png",
"name": "缺陷",
"subtask": false
}
]
}
]
}
我想取
projects.issuetypes.id和projects.issuetypes.name
// 解析后数据
[
{
"issueTypeId": "10002",
"issueTypeName": "任务"
},
{
"issueTypeId": "10003",
"issueTypeName": "开发子任务"
},
{
"issueTypeId": "10001",
"issueTypeName": "故事"
},
{
"issueTypeId": "10202",
"issueTypeName": "测试用例"
},
{
"issueTypeId": "10203",
"issueTypeName": "测试计划"
},
{
"issueTypeId": "10204",
"issueTypeName": "缺陷"
}
]
代码如下
/**
* @author Ledison
* @date 2022/2/28
*/
public class JsonAdapter extends AbstractAdapter implements AdapterExecute {
public JsonAdapter(Map map) {
super(map);
}
private static void parseObject(String data, List
使用方式
Map map = new HashMap<>();
// 字段映射
map.put("projects.issuetypes.id","issueTypeId");
map.put("projects.issuetypes.name","issueTypeName");
JsonAdapter jsonAdapter = new JsonAdapter(map);
// 原始数据
String data = "";
List> maps = jsonAdapter.allData(data);