|
14 | 14 | import java.io.IOException; |
15 | 15 | import java.lang.reflect.Type; |
16 | 16 | import java.util.HashMap; |
| 17 | +import java.util.List; |
17 | 18 |
|
18 | 19 | public class TestDemo extends TestCase { |
19 | 20 | public void test_bind_api() throws IOException { |
@@ -169,4 +170,62 @@ public void test_deserialize() { |
169 | 170 | String str = "{\"port\":13110} "; |
170 | 171 | JsonIterator.deserialize(str.getBytes(), HashMap.class); |
171 | 172 | } |
| 173 | + |
| 174 | + public static class CollectionResponse<T> { |
| 175 | + public List<T> results; |
| 176 | + } |
| 177 | + |
| 178 | + public static class Feed { |
| 179 | + public String id; |
| 180 | + public String owner; |
| 181 | + public String name; |
| 182 | + } |
| 183 | + |
| 184 | + public void test_generics() { |
| 185 | + CollectionResponse<Feed> objs = JsonIterator.deserialize("{\n" + |
| 186 | + "\"count\": 1,\n" + |
| 187 | + "\"next\": null,\n" + |
| 188 | + "\"previous\": null,\n" + |
| 189 | + "\"results\": [\n" + |
| 190 | + "{\n" + |
| 191 | + "\"id\": \"f560fccb-4020-43c1-8a27-92507ef625bd\",\n" + |
| 192 | + "\"search_terms\": [\n" + |
| 193 | + "\"gigi hadid\"\n" + |
| 194 | + "],\n" + |
| 195 | + "\"owner\": \"...\",\n" + |
| 196 | + "\"egress_nodes\": [\n" + |
| 197 | + "\"DE\"\n" + |
| 198 | + "],\n" + |
| 199 | + "\"status\": \"ACTIVE\",\n" + |
| 200 | + "\"expires_at\": null,\n" + |
| 201 | + "\"available_sources\": [\n" + |
| 202 | + "\"92c784ae-b7bf-4434-a6cc-740109d91cc8\"\n" + |
| 203 | + "],\n" + |
| 204 | + "\"available_egress_nodes\": [\n" + |
| 205 | + "\"DE\"\n" + |
| 206 | + "],\n" + |
| 207 | + "\"created_at\": \"2017-07-27T13:29:20.935108Z\",\n" + |
| 208 | + "\"name\": \"Test\",\n" + |
| 209 | + "\"description\": \"\",\n" + |
| 210 | + "\"start_date\": null,\n" + |
| 211 | + "\"end_date\": null,\n" + |
| 212 | + "\"match_all_include\": false,\n" + |
| 213 | + "\"velocity\": 0.0666666666666667,\n" + |
| 214 | + "\"storage_consumption\": 0.000011026778,\n" + |
| 215 | + "\"consumption\": 0.000120833333333333,\n" + |
| 216 | + "\"persistence_enabled\": true,\n" + |
| 217 | + "\"sources\": [\n" + |
| 218 | + "\"92c784ae-b7bf-4434-a6cc-740109d91cc8\"\n" + |
| 219 | + "],\n" + |
| 220 | + "\"permissions\": {\n" + |
| 221 | + "\"has_read_access\": true,\n" + |
| 222 | + "\"has_write_access\": true,\n" + |
| 223 | + "\"has_share_access\": true,\n" + |
| 224 | + "\"has_ownership\": true\n" + |
| 225 | + "}\n" + |
| 226 | + "}\n" + |
| 227 | + "]\n" + |
| 228 | + "}", new TypeLiteral<CollectionResponse<Feed>>(){}); |
| 229 | + assertEquals("f560fccb-4020-43c1-8a27-92507ef625bd", objs.results.get(0).id); |
| 230 | + } |
172 | 231 | } |
0 commit comments