forked from json-iterator/java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTestGenerics.java
More file actions
57 lines (47 loc) · 1.52 KB
/
TestGenerics.java
File metadata and controls
57 lines (47 loc) · 1.52 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
package com.jsoniter.output;
import junit.framework.TestCase;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class TestGenerics extends TestCase {
static {
// JsonStream.setMode(EncodingMode.DYNAMIC_MODE);
}
private ByteArrayOutputStream baos;
private JsonStream stream;
public void setUp() {
baos = new ByteArrayOutputStream();
stream = new JsonStream(baos, 4096);
}
public interface TestObject6Interface<A> {
A getHello();
}
public static class TestObject6 implements TestObject6Interface<Integer> {
public Integer getHello() {
return 0;
}
}
public void test_inherited_getter_is_not_duplicate() throws IOException {
TestObject6 obj = new TestObject6();
stream.writeVal(obj);
stream.close();
assertEquals("{\"hello\":0}", baos.toString());
}
public static class TestObject7 {
public List<?> field;
public Map<?, ?> field2;
}
public void test_wildcard() throws IOException {
TestObject7 obj = new TestObject7();
ArrayList<Integer> list = new ArrayList<Integer>();
list.add(1);
obj.field = list;
HashMap<String, Object> map = new HashMap<String, Object>();
map.put("hello", 1);
obj.field2 = map;
assertEquals("{\"field\":[1],\"field2\":{\"hello\":1}}", JsonStream.serialize(obj));
}
}