1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.juneau.json;
18
19 import static org.junit.jupiter.api.Assertions.*;
20
21 import java.util.function.*;
22
23 import org.apache.juneau.*;
24 import org.apache.juneau.json.annotation.*;
25 import org.apache.juneau.reflect.*;
26 import org.apache.juneau.svl.*;
27 import org.junit.jupiter.api.*;
28
29
30
31
32 class JsonConfigAnnotationTest extends TestBase {
33
34 private static void check(String expected, Object o) {
35 assertEquals(expected, TO_STRING.apply(o));
36 }
37
38 private static final Function<Object,String> TO_STRING = Object::toString;
39
40 static VarResolverSession sr = VarResolver.create().vars(XVar.class).build().createSession();
41
42
43
44
45
46 @JsonConfig(
47 addBeanTypes="$X{true}",
48 escapeSolidus="$X{true}",
49 simpleAttrs="$X{true}",
50 validateEnd="$X{true}"
51 )
52 static class A {}
53 static ClassInfo a = ClassInfo.of(A.class);
54
55 @Test void basicSerializer() {
56 var al = AnnotationWorkList.of(sr, a.getAnnotationList());
57 var x = JsonSerializer.create().apply(al).build().getSession();
58 check("true", x.isAddBeanTypes());
59 check("true", x.isEscapeSolidus());
60 check("true", x.isSimpleAttrs());
61 }
62
63 @Test void basicParser() {
64 var al = AnnotationWorkList.of(sr, a.getAnnotationList());
65 var x = JsonParser.create().apply(al).build().getSession();
66 check("true", x.isValidateEnd());
67 }
68
69
70
71
72
73 @JsonConfig()
74 static class B {}
75 static ClassInfo b = ClassInfo.of(B.class);
76
77 @Test void noValuesSerializer() {
78 var al = AnnotationWorkList.of(sr, b.getAnnotationList());
79 var x = JsonSerializer.create().apply(al).build().getSession();
80 check("false", x.isAddBeanTypes());
81 check("false", x.isEscapeSolidus());
82 check("false", x.isSimpleAttrs());
83 }
84
85 @Test void noValuesParser() {
86 var al = AnnotationWorkList.of(sr, b.getAnnotationList());
87 var x = JsonParser.create().apply(al).build().getSession();
88 check("false", x.isValidateEnd());
89 }
90
91
92
93
94
95 static class C {}
96 static ClassInfo c = ClassInfo.of(C.class);
97
98 @Test void noAnnotationSerializer() {
99 var al = AnnotationWorkList.of(sr, c.getAnnotationList());
100 var x = JsonSerializer.create().apply(al).build().getSession();
101 check("false", x.isAddBeanTypes());
102 check("false", x.isEscapeSolidus());
103 check("false", x.isSimpleAttrs());
104 }
105
106 @Test void noAnnotationParser() {
107 var al = AnnotationWorkList.of(sr, c.getAnnotationList());
108 var x = JsonParser.create().apply(al).build().getSession();
109 check("false", x.isValidateEnd());
110 }
111 }