forked from json-iterator/java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTestAnnotationJsonObject.java
More file actions
64 lines (53 loc) · 1.9 KB
/
TestAnnotationJsonObject.java
File metadata and controls
64 lines (53 loc) · 1.9 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
package com.jsoniter;
import com.jsoniter.annotation.JsonExtraProperties;
import com.jsoniter.annotation.JsonObject;
import com.jsoniter.any.Any;
import com.jsoniter.spi.JsonException;
import junit.framework.TestCase;
import java.io.IOException;
import java.util.Map;
public class TestAnnotationJsonObject extends TestCase {
@JsonObject(asExtraForUnknownProperties = true)
public static class TestObject9 {
@JsonExtraProperties
public Map<String, Any> extraProperties;
}
public void test_extra_properties() throws IOException {
JsonIterator iter = JsonIterator.parse("{\"field1\": 100}");
TestObject9 obj = iter.read(TestObject9.class);
assertEquals(100, obj.extraProperties.get("field1").toInt());
}
@JsonObject(asExtraForUnknownProperties = true)
public static class TestObject13 {
}
public void test_unknown_properties() throws IOException {
JsonIterator iter = JsonIterator.parse("{\"field-1\": 100, \"field-1\": 101}");
try {
iter.read(TestObject13.class);
fail();
} catch (JsonException e) {
System.out.println(e);
}
}
@JsonObject(unknownPropertiesBlacklist = {"field1"})
public static class TestObject15 {
}
public void test_unknown_properties_blacklist() throws IOException {
JsonIterator iter = JsonIterator.parse("{\"field1\": 100}");
try {
iter.read(TestObject15.class);
fail();
} catch (JsonException e) {
System.out.println(e);
}
}
@JsonObject(asExtraForUnknownProperties = true)
public static class TestObject14 {
public int id;
}
public void test_no_unknown_properties() throws IOException {
String json = "{ \"id\": 100 }";
TestObject14 obj = JsonIterator.deserialize(json, TestObject14.class);
assertEquals(100, obj.id);
}
}