一、需求
原来已经有了自爬取的APP列表解析信息,现在增加一个渠道的APP列表,字段意思一样,但是字段名不一样。为了方便数据存储不变和下游部门代码不变,决定存储在一起,这就需要将字段映射成一样的。
二、实现
1、原来代码
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98package com.credithc.sea.entity.deviceinfo; import com.fasterxml.jackson.annotation.JsonProperty; import java.util.ArrayList; import java.util.Collections; import java.util.List; public class AppListInfo extends DeviceInfoBase { private List<AppInfo> apps = new ArrayList<>(); public List<AppInfo> getApps() { return apps; } public void setApps(List<AppInfo> apps) { if (apps == null) this.apps = Collections.emptyList(); else this.apps = apps; } public static class AppInfo { @JsonProperty(value = "app_label") private String appLabel; //App名称 @JsonProperty(value = "pkg_name") private String pkgName; //App包名 @JsonProperty(value = "firstInstallTime") private String firstInstallTime; @JsonProperty(value = "lastUpdateTime") private String lastUpdateTime; public String getFirstInstallTime() { return firstInstallTime; } public void setFirstInstallTime(String firstInstallTime) { this.firstInstallTime = firstInstallTime; } public String getLastUpdateTime() { return lastUpdateTime; } public void setLastUpdateTime(String lastUpdateTime) { this.lastUpdateTime = lastUpdateTime; } public String getAppLabel() { return appLabel; } public void setAppLabel(String appLabel) { this.appLabel = appLabel; } public String getPkgName() { return pkgName; } public void setPkgName(String pkgName) { this.pkgName = pkgName; } @Override public boolean equals(Object o) { if (this == o) { return true; } if (!(o instanceof AppInfo)) { return false; } AppInfo appInfo = (AppInfo) o; if (appLabel != null ? !appLabel.equals(appInfo.appLabel) : appInfo.appLabel != null) { return false; } if (firstInstallTime != null ? !firstInstallTime.equals(appInfo.firstInstallTime) : appInfo.firstInstallTime != null) { return false; } if (lastUpdateTime != null ? !lastUpdateTime.equals(appInfo.lastUpdateTime) : appInfo.lastUpdateTime != null) { return false; } return pkgName != null ? pkgName.equals(appInfo.pkgName) : appInfo.pkgName == null; } @Override public int hashCode() { int result = appLabel != null ? appLabel.hashCode() : 0; result = 31 * result + (pkgName != null ? pkgName.hashCode() : 0); return result; } } }
对应需要解析的数据是:
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23{ "params": { "crawler_time": "2020-01-02 08:20:22", "biz_channel": "API001", "user_id": "0000000001", "idCard": "证件号码", "app_ver": "app_ver", "biz_type": "ISS001", "imei": "imei", "crawler_type": "lend", "type": "APP_LIST", "apps": [ { "app_label": "Solusindo", "pkg_name": "com.ecreditpal.solusindo" }, { "app_label": "搜狗浏览器", "pkg_name": "sogou.mobile.explorer" } ] } }
后来需要解析的是:
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23{ "params": { "crawler_time": "2020-01-02 08:20:22", "biz_channel": "API001", "user_id": "0000000002", "idCard": "证件号码", "app_ver": "app_ver", "biz_type": "ISS001", "imei": "imei", "crawler_type": "lend", "type": "APP_LIST", "apps": [ { "app_name": "Solusindo", "package_name": "com.ecreditpal.solusindo" }, { "app_label": "搜狗浏览器", "pkg_name": "sogou.mobile.explorer" } ] } }
可以看到,APP名原来是app_label、pkg_name,新渠道是app_name、package_name,需要统一存储为app_label、pkg_name。
实现:
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108package com.credithc.sea.entity.deviceinfo; import com.fasterxml.jackson.annotation.JsonProperty; import java.util.ArrayList; import java.util.Collections; import java.util.List; public class AppListInfo extends DeviceInfoBase { private List<AppInfo> apps = new ArrayList<>(); public List<AppInfo> getApps() { return apps; } public void setApps(List<AppInfo> apps) { if (apps == null) this.apps = Collections.emptyList(); else this.apps = apps; } public static class AppInfo { @JsonProperty(value = "app_label") private String appLabel; //App名称 @JsonProperty(value = "pkg_name") private String pkgName; //App包名 @JsonProperty(value = "firstInstallTime") private String firstInstallTime; @JsonProperty(value = "lastUpdateTime") private String lastUpdateTime; public String getFirstInstallTime() { return firstInstallTime; } public void setFirstInstallTime(String firstInstallTime) { this.firstInstallTime = firstInstallTime; } public String getLastUpdateTime() { return lastUpdateTime; } public void setLastUpdateTime(String lastUpdateTime) { this.lastUpdateTime = lastUpdateTime; } public String getAppLabel() { return appLabel; } public void setAppLabel(String appLabel) { this.appLabel = appLabel; } @JsonProperty(value = "app_name") public void setAppName(String appName) { this.appLabel = appName; } @JsonProperty(value ="package_name") public void packageName(String packageName) { this.pkgName = packageName; } public String getPkgName() { return pkgName; } public void setPkgName(String pkgName) { this.pkgName = pkgName; } @Override public boolean equals(Object o) { if (this == o) { return true; } if (!(o instanceof AppInfo)) { return false; } AppInfo appInfo = (AppInfo) o; if (appLabel != null ? !appLabel.equals(appInfo.appLabel) : appInfo.appLabel != null) { return false; } if (firstInstallTime != null ? !firstInstallTime.equals(appInfo.firstInstallTime) : appInfo.firstInstallTime != null) { return false; } if (lastUpdateTime != null ? !lastUpdateTime.equals(appInfo.lastUpdateTime) : appInfo.lastUpdateTime != null) { return false; } return pkgName != null ? pkgName.equals(appInfo.pkgName) : appInfo.pkgName == null; } @Override public int hashCode() { int result = appLabel != null ? appLabel.hashCode() : 0; result = 31 * result + (pkgName != null ? pkgName.hashCode() : 0); return result; } } }
增加代码:
复制代码
1
2
3
4
5
6
7
8
9@JsonProperty(value = "app_name") public void setAppName(String appName) { this.appLabel = appName; } @JsonProperty(value ="package_name") public void packageName(String packageName) { this.pkgName = packageName; }
存数结果:
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26{ "queryDate": "2020-01-17 15:28:44", "type": "APP_LIST", "idCard": "证件号码", "imei": "imei", "apps": [ { "app_label": "Solusindo", "pkg_name": "com.ecreditpal.solusindo", "firstInstallTime": null, "lastUpdateTime": null }, { "app_label": "搜狗浏览器", "pkg_name": "sogou.mobile.explorer", "firstInstallTime": null, "lastUpdateTime": null } ], "user_id": "0000000002", "biz_channel": "API001", "biz_type": "ISS001", "app_ver": "app_ver", "crawler_time": "2020-01-02 08:20:22", "crawler_type": "lend" }
最后
以上就是搞怪茉莉最近收集整理的关于使用@JsonProperty将多个类似数据源写在一起的全部内容,更多相关使用@JsonProperty将多个类似数据源写在一起内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复