forked from json-iterator/java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTestObject.java
More file actions
70 lines (56 loc) · 1.83 KB
/
TestObject.java
File metadata and controls
70 lines (56 loc) · 1.83 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
package com.jsoniter.output;
import com.jsoniter.annotation.JsonIgnore;
import com.jsoniter.annotation.JsoniterAnnotationSupport;
import com.jsoniter.spi.TypeLiteral;
import junit.framework.TestCase;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
public class TestObject extends TestCase {
static {
JsoniterAnnotationSupport.enable();
// JsonStream.setMode(EncodingMode.REFLECTION_MODE);
}
private ByteArrayOutputStream baos;
private JsonStream stream;
public void setUp() {
baos = new ByteArrayOutputStream();
stream = new JsonStream(baos, 4096);
}
public static class TestObject1 {
public String field1;
}
public void test_field() throws IOException {
TestObject1 obj = new TestObject1();
obj.field1 = "hello";
stream.writeVal(obj);
stream.close();
assertEquals("{'field1':'hello'}".replace('\'', '"'), baos.toString());
}
public static class TestObject2 {
@JsonIgnore
private String field1;
public String getField1() {
return field1;
}
}
public void test_getter() throws IOException {
TestObject2 obj = new TestObject2();
obj.field1 = "hello";
stream.writeVal(obj);
stream.close();
assertEquals("{'field1':'hello'}".replace('\'', '"'), baos.toString());
}
public void test_null() throws IOException {
stream.writeVal(new TypeLiteral<TestObject2>() {
}, null);
stream.close();
assertEquals("null".replace('\'', '"'), baos.toString());
}
public static class TestObject3 {
}
public void test_empty_object() throws IOException {
stream.writeVal(new TestObject3());
stream.close();
assertEquals("{}".replace('\'', '"'), baos.toString());
}
}