forked from json-iterator/java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTestAnnotation.java
More file actions
63 lines (52 loc) · 1.65 KB
/
TestAnnotation.java
File metadata and controls
63 lines (52 loc) · 1.65 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
package com.jsoniter.output;
import com.jsoniter.annotation.JsonIgnore;
import com.jsoniter.annotation.JsonProperty;
import com.jsoniter.annotation.JsoniterAnnotationSupport;
import com.jsoniter.spi.Encoder;
import junit.framework.TestCase;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
public class TestAnnotation extends TestCase {
static {
JsoniterAnnotationSupport.enable();
}
private ByteArrayOutputStream baos;
private JsonStream stream;
public void setUp() {
baos = new ByteArrayOutputStream();
stream = new JsonStream(baos, 4096);
}
public static class TestObject1 {
@JsonProperty(to = {"field-1"})
public String field1;
}
public void test_property() throws IOException {
TestObject1 obj = new TestObject1();
obj.field1 = "hello";
stream.writeVal(obj);
stream.close();
assertEquals("{\"field-1\":\"hello\"}", baos.toString());
}
public static class TestObject2 {
@JsonProperty(encoder = Encoder.StringIntEncoder.class)
public int field1;
}
public void test_encoder() throws IOException {
TestObject2 obj = new TestObject2();
obj.field1 = 100;
stream.writeVal(obj);
stream.close();
assertEquals("{\"field1\":\"100\"}", baos.toString());
}
public static class TestObject3 {
@JsonIgnore
public int field1;
}
public void test_ignore() throws IOException {
TestObject3 obj = new TestObject3();
obj.field1 = 100;
stream.writeVal(obj);
stream.close();
assertEquals("{}", baos.toString());
}
}