Skip to content

Commit 026af26

Browse files
committed
#92 fix generics support
1 parent 114b091 commit 026af26

File tree

2 files changed

+61
-2
lines changed

2 files changed

+61
-2
lines changed

src/main/java/com/jsoniter/spi/ClassDescriptor.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ private ClassDescriptor() {
2626

2727
public static ClassDescriptor getDecodingClassDescriptor(ClassInfo classInfo, boolean includingPrivate) {
2828
Class clazz = classInfo.clazz;
29-
Map<String, Type> lookup = collectTypeVariableLookup(clazz);
29+
Map<String, Type> lookup = collectTypeVariableLookup(classInfo.type);
3030
ClassDescriptor desc = new ClassDescriptor();
3131
desc.classInfo = classInfo;
3232
desc.clazz = clazz;
@@ -82,7 +82,7 @@ public static ClassDescriptor getDecodingClassDescriptor(ClassInfo classInfo, bo
8282

8383
public static ClassDescriptor getEncodingClassDescriptor(ClassInfo classInfo, boolean includingPrivate) {
8484
Class clazz = classInfo.clazz;
85-
Map<String, Type> lookup = collectTypeVariableLookup(clazz);
85+
Map<String, Type> lookup = collectTypeVariableLookup(classInfo.type);
8686
ClassDescriptor desc = new ClassDescriptor();
8787
desc.classInfo = classInfo;
8888
desc.clazz = clazz;

src/test/java/com/jsoniter/TestDemo.java

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import java.io.IOException;
1515
import java.lang.reflect.Type;
1616
import java.util.HashMap;
17+
import java.util.List;
1718

1819
public class TestDemo extends TestCase {
1920
public void test_bind_api() throws IOException {
@@ -169,4 +170,62 @@ public void test_deserialize() {
169170
String str = "{\"port\":13110} ";
170171
JsonIterator.deserialize(str.getBytes(), HashMap.class);
171172
}
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+
}
172231
}

0 commit comments

Comments
 (0)