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
31 lines (26 loc) · 1.02 KB
/
TestAnnotation.java
File metadata and controls
31 lines (26 loc) · 1.02 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
package com.jsoniter;
import com.jsoniter.annotation.jsoniter.JsonIgnore;
import com.jsoniter.annotation.jsoniter.JsonProperty;
import com.jsoniter.annotation.jsoniter.JsoniterAnnotationSupport;
import junit.framework.TestCase;
import java.io.IOException;
public class TestAnnotation extends TestCase {
public static class AnnotatedObject {
@JsonProperty("field-1")
public int field1;
@JsonIgnore
public int field2;
}
public void test_rename() throws IOException {
JsoniterAnnotationSupport.enable();
JsonIterator iter = JsonIterator.parse("{'field-1': 100}".replace('\'', '"'));
AnnotatedObject obj = iter.read(AnnotatedObject.class);
assertEquals(100, obj.field1);
}
public void test_ignore() throws IOException {
JsoniterAnnotationSupport.enable();
JsonIterator iter = JsonIterator.parse("{'field2': 100}".replace('\'', '"'));
AnnotatedObject obj = iter.read(AnnotatedObject.class);
assertEquals(0, obj.field2);
}
}