RestTest.java
7.42 KB
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
package cn.com.glsx.test;
import cn.com.glsx.admin.modules.model.SimpleTreeModel;
import cn.com.glsx.usercenter.api.dto.response.User;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.TypeReference;
import com.glsx.plat.core.web.R;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.reflect.TypeToken;
import java.util.List;
public class RestTest {
public static void main(String[] args) {
// RestTemplate restTemplate = new RestTemplate();
// String url = "";
// R messageList = restTemplate.getForObject(url, R.class);
// test();
testOrg();
}
public static void test() {
String str = "{\"code\":200,\"data\":{\"id\":1,\"username\":\"超级管理员\",\"account\":\"admin\",\"gender\":0,\"phoneNumber\":\"13800138000\",\"portrait\":null,\"email\":null},\"message\":\"success\"}";
// R r = JSON.parseObject(str, R.class, new ParserConfig(), Feature.values());
// System.out.println(r);
R<User> r2 = JSON.parseObject(str, new TypeReference<R<User>>() {
});
System.out.println(r2);
Gson gson = new GsonBuilder().serializeNulls().create();
R<User> r3 = gson.fromJson(str, new TypeToken<R<User>>() {
}.getType());
System.out.println(r3);
}
public static void testOrg() {
String json = "[\n" +
" {\n" +
" \"userNumber\": 0,\n" +
" \"children\": [\n" +
" {\n" +
" \"userNumber\": 0,\n" +
" \"children\": [\n" +
" {\n" +
" \"userNumber\": 0,\n" +
" \"children\": [\n" +
" {\n" +
" \"userNumber\": 0,\n" +
" \"children\": [\n" +
" {\n" +
" \"userNumber\": 3,\n" +
" \"children\": [\n" +
" {\n" +
" \"userNumber\": 1,\n" +
" \"children\": [],\n" +
" \"id\": 165,\n" +
" \"origin\": {\n" +
" \"orgId\": 165,\n" +
" \"orgName\": \"广州恒福店\",\n" +
" \"parentId\": 162,\n" +
" \"tenantId\": 33,\n" +
" \"isRoot\": 0\n" +
" },\n" +
" \"depth\": 5,\n" +
" \"parentId\": 162,\n" +
" \"label\": \"广州恒福店\"\n" +
" },\n" +
" {\n" +
" \"userNumber\": 1,\n" +
" \"children\": [],\n" +
" \"id\": 169,\n" +
" \"origin\": {\n" +
" \"orgId\": 169,\n" +
" \"orgName\": \"广州恒源店\",\n" +
" \"parentId\": 162,\n" +
" \"tenantId\": 33,\n" +
" \"isRoot\": 0\n" +
" },\n" +
" \"depth\": 5,\n" +
" \"parentId\": 162,\n" +
" \"label\": \"广州恒源店\"\n" +
" }\n" +
" ],\n" +
" \"id\": 162,\n" +
" \"origin\": {\n" +
" \"orgId\": 162,\n" +
" \"orgName\": \"广州店\",\n" +
" \"parentId\": 161,\n" +
" \"tenantId\": 33,\n" +
" \"isRoot\": 0\n" +
" },\n" +
" \"depth\": 4,\n" +
" \"parentId\": 161,\n" +
" \"label\": \"广州店\"\n" +
" }\n" +
" ],\n" +
" \"id\": 161,\n" +
" \"origin\": {\n" +
" \"orgId\": 161,\n" +
" \"orgName\": \"广州市\",\n" +
" \"parentId\": 160,\n" +
" \"tenantId\": 33,\n" +
" \"isRoot\": 0\n" +
" },\n" +
" \"depth\": 3,\n" +
" \"parentId\": 160,\n" +
" \"label\": \"广州市\"\n" +
" }\n" +
" ],\n" +
" \"id\": 160,\n" +
" \"origin\": {\n" +
" \"orgId\": 160,\n" +
" \"orgName\": \"广东省\",\n" +
" \"parentId\": 157,\n" +
" \"tenantId\": 33,\n" +
" \"isRoot\": 0\n" +
" },\n" +
" \"depth\": 2,\n" +
" \"parentId\": 157,\n" +
" \"label\": \"广东省\"\n" +
" }\n" +
" ],\n" +
" \"id\": 157,\n" +
" \"origin\": {\n" +
" \"orgId\": 157,\n" +
" \"orgName\": \"华南区\",\n" +
" \"parentId\": 156,\n" +
" \"tenantId\": 33,\n" +
" \"isRoot\": 0\n" +
" },\n" +
" \"depth\": 1,\n" +
" \"parentId\": 156,\n" +
" \"label\": \"华南区\"\n" +
" }\n" +
" ],\n" +
" \"id\": 156,\n" +
" \"origin\": {\n" +
" \"orgId\": 156,\n" +
" \"orgName\": \"广汽本田\",\n" +
" \"parentId\": 156,\n" +
" \"tenantId\": 33,\n" +
" \"isRoot\": 1\n" +
" },\n" +
" \"depth\": 0,\n" +
" \"parentId\": 156,\n" +
" \"label\": \"广汽本田\"\n" +
" }\n" +
" ]";
Gson gson = new GsonBuilder().serializeNulls().create();
List<SimpleTreeModel> r3 = gson.fromJson(json, new TypeToken<List<SimpleTreeModel>>() {
}.getType());
System.out.println(r3);
}
}