-
Notifications
You must be signed in to change notification settings - Fork 2k
Expand file tree
/
Copy pathJaxbTest.java
More file actions
158 lines (125 loc) · 3.16 KB
/
JaxbTest.java
File metadata and controls
158 lines (125 loc) · 3.16 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
import java.util.List;
import javax.xml.bind.annotation.XmlEnum;
import javax.xml.bind.annotation.XmlRegistry;
import javax.xml.bind.annotation.XmlType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.Marshaller;
import javax.xml.bind.Unmarshaller;
public class JaxbTest {
@XmlRegistry
public static class ObjectFactory {
public AnnotatedObject createAnnotatedObject() {
return new AnnotatedObject();
}
public PublicMemberObject createPublicMemberObject() {
return new PublicMemberObject();
}
public FieldObject createFieldObject() {
return new FieldObject();
}
}
/**
* Verify that annotated fields work correctly.
*/
@XmlType
@XmlAccessorType(XmlAccessType.NONE)
public static class AnnotatedObject {
@XmlElement
private LiveEnum liveEnum;
@XmlElement
public List<UnnannotatedLiveClass> classes;
private LiveEnum liveEnumProp;
private LiveEnum deadLink;
public void setLiveEnum(LiveEnum liveEnum) {
this.liveEnum = liveEnum;
}
public LiveEnum getLiveEnum() {
return liveEnum;
}
@XmlElement
public void setLiveEnumProp(LiveEnum liveEnumProp) {
this.liveEnumProp = liveEnumProp;
}
public LiveEnum getLiveEnumProp() {
return liveEnumProp;
}
public void setDeadLink(LiveEnum deadLink) {
this.deadLink = deadLink;
}
public LiveEnum getDeadLink() {
return deadLink;
}
// Live marshal and unmarshal methods
public void afterUnmarshal(Unmarshaller a, Object b) {
}
public void beforeUnmarshal(Unmarshaller a, Object b) {
}
public void afterMarshal(Marshaller a, Object b) {
}
public void beforeMarshal(Marshaller a, Object b) {
}
}
/**
* Using default XmlAccessType (PUBLIC_MEMBER), verify that the properties are identified.
*/
@XmlType
public static class PublicMemberObject {
private LiveEnum liveEnum;
public void setLiveEnum(LiveEnum liveEnum) {
this.liveEnum = liveEnum;
}
public LiveEnum getLiveEnum() {
return liveEnum;
}
}
/**
* Verify that the field is picked up.
*/
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType
public static class FieldObject {
private LiveEnum liveEnum;
public void setLiveEnum(LiveEnum liveEnum) {
this.liveEnum = liveEnum;
}
public LiveEnum getLiveEnum() {
return liveEnum;
}
}
/**
* A class whose setter/getter would be live, but the constructor is not live.
*/
@XmlType
public static class DeadPublicMemberObject {
private LiveEnum deadProperty;
public void setDeadProperty(LiveEnum deadProperty) {
this.deadProperty = deadProperty;
}
public LiveEnum getDeadProperty() {
return deadProperty;
}
public static void liveMethod() { }
}
@XmlEnum
public static enum LiveEnum {
A;
}
/**
* A class that is live because it is referred to in AnnotatedObject.
*/
public static class UnnannotatedLiveClass {
@XmlElement
private LiveEnum liveEnum;
public void setLiveEnum(LiveEnum liveEnum) {
this.liveEnum = liveEnum;
}
public LiveEnum getLiveEnum() {
return liveEnum;
}
}
public static void main(String[] args) {
DeadPublicMemberObject.liveMethod();
}
}