1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.juneau;
18
19 import static org.apache.juneau.TestUtils.*;
20
21 import java.beans.*;
22 import java.util.*;
23
24 import org.apache.juneau.annotation.*;
25 import org.apache.juneau.json.*;
26 import org.junit.jupiter.api.*;
27
28 class BasicBeans_Test extends TestBase {
29
30
31
32
33
34 public static class A1 {
35 public int f1;
36 public transient int f2;
37
38 public static A1 create() {
39 var x = new A1();
40 x.f1 = 1;
41 x.f2 = 2;
42 return x;
43 }
44 }
45
46 @BeanConfig(disableIgnoreTransientFields="true")
47 public static class A {}
48
49 @Test void a01_testTransientFieldsIgnored() {
50 assertJson("{f1:1}", A1.create());
51 }
52
53 @Test void a02_testTransientFieldsIgnored_overrideSetting() {
54 assertSerialized(A1.create(), Json5Serializer.DEFAULT.copy().disableIgnoreTransientFields().build(), "{f1:1,f2:2}");
55 }
56
57 @Test void a03_testTransientFieldsIgnored_overrideAnnotation() {
58 assertSerialized(A1.create(), Json5Serializer.DEFAULT.copy().applyAnnotations(A.class).build(), "{f1:1,f2:2}");
59 }
60
61 public static class A2 {
62 public int f1;
63
64 private int f2;
65 public void setF2(int v) { f2 = v; }
66 @Transient public int getF2() { return f2; }
67
68 public static A2 create() {
69 var x = new A2();
70 x.f1 = 1;
71 x.f2 = 2;
72 return x;
73 }
74 }
75
76 @Test void a04_testTransientMethodsIgnored() {
77 assertJson("{f1:1}", A2.create());
78 }
79
80
81
82
83
84 public static class B {
85 @Beanp(name="*")
86 public Map<String,Integer> f1 = new TreeMap<>();
87
88 public static B create() {
89 var x = new B();
90 x.f1.put("a", 1);
91 return x;
92 }
93 }
94
95 @Test void b01_beanWithDynaProperty() throws Exception {
96 assertJson("{a:1}", B.create());
97
98 var b = JsonParser.DEFAULT.parse("{a:1}", B.class);
99 assertJson("{a:1}", b);
100 }
101 }