20
20
21
21
package com .arangodb .velocypack ;
22
22
23
+ import java .lang .annotation .Annotation ;
23
24
import java .lang .reflect .Array ;
24
25
import java .lang .reflect .InvocationTargetException ;
25
26
import java .lang .reflect .ParameterizedType ;
37
38
import java .util .UUID ;
38
39
39
40
import com .arangodb .velocypack .VPackBuilder .BuilderOptions ;
41
+ import com .arangodb .velocypack .annotations .Expose ;
42
+ import com .arangodb .velocypack .annotations .SerializedName ;
40
43
import com .arangodb .velocypack .exception .VPackException ;
41
44
import com .arangodb .velocypack .exception .VPackParserException ;
42
45
import com .arangodb .velocypack .internal .DefaultVPackBuilderOptions ;
@@ -77,6 +80,8 @@ public static class Builder {
77
80
private final BuilderOptions builderOptions ;
78
81
private boolean serializeNullValues ;
79
82
private VPackFieldNamingStrategy fieldNamingStrategy ;
83
+ private final Map <Class <? extends Annotation >, VPackAnnotationFieldFilter <? extends Annotation >> annotationFieldFilter ;
84
+ private final Map <Class <? extends Annotation >, VPackAnnotationFieldNaming <? extends Annotation >> annotationFieldNaming ;
80
85
81
86
public Builder () {
82
87
super ();
@@ -86,6 +91,8 @@ public Builder() {
86
91
instanceCreators = new HashMap <Type , VPackInstanceCreator <?>>();
87
92
builderOptions = new DefaultVPackBuilderOptions ();
88
93
serializeNullValues = false ;
94
+ annotationFieldFilter = new HashMap <Class <? extends Annotation >, VPackAnnotationFieldFilter <? extends Annotation >>();
95
+ annotationFieldNaming = new HashMap <Class <? extends Annotation >, VPackAnnotationFieldNaming <? extends Annotation >>();
89
96
90
97
instanceCreators .put (Collection .class , VPackInstanceCreators .COLLECTION );
91
98
instanceCreators .put (List .class , VPackInstanceCreators .LIST );
@@ -139,6 +146,24 @@ public Builder() {
139
146
deserializers .put (java .sql .Timestamp .class , VPackDeserializers .SQL_TIMESTAMP );
140
147
deserializers .put (VPackSlice .class , VPackDeserializers .VPACK );
141
148
deserializers .put (UUID .class , VPackDeserializers .UUID );
149
+
150
+ annotationFieldFilter .put (Expose .class , new VPackAnnotationFieldFilter <Expose >() {
151
+ @ Override
152
+ public boolean serialize (final Expose annotation ) {
153
+ return annotation .serialize ();
154
+ }
155
+
156
+ @ Override
157
+ public boolean deserialize (final Expose annotation ) {
158
+ return annotation .deserialize ();
159
+ }
160
+ });
161
+ annotationFieldNaming .put (SerializedName .class , new VPackAnnotationFieldNaming <SerializedName >() {
162
+ @ Override
163
+ public String name (final SerializedName annotation ) {
164
+ return annotation .value ();
165
+ }
166
+ });
142
167
}
143
168
144
169
public <T > VPack .Builder registerSerializer (final Type type , final VPackSerializer <T > serializer ) {
@@ -189,17 +214,33 @@ public VPack.Builder fieldNamingStrategy(final VPackFieldNamingStrategy fieldNam
189
214
return this ;
190
215
}
191
216
217
+ public <A extends Annotation > VPack .Builder annotationFieldFilter (
218
+ final Class <A > type ,
219
+ final VPackAnnotationFieldFilter <A > fieldFilter ) {
220
+ annotationFieldFilter .put (type , fieldFilter );
221
+ return this ;
222
+ }
223
+
224
+ public <A extends Annotation > VPack .Builder annotationFieldNaming (
225
+ final Class <A > type ,
226
+ final VPackAnnotationFieldNaming <A > fieldNaming ) {
227
+ annotationFieldNaming .put (type , fieldNaming );
228
+ return this ;
229
+ }
230
+
192
231
public VPack build () {
193
232
return new VPack (serializers , deserializers , instanceCreators , builderOptions , serializeNullValues ,
194
- fieldNamingStrategy , deserializersByName );
233
+ fieldNamingStrategy , deserializersByName , annotationFieldFilter , annotationFieldNaming );
195
234
}
196
235
197
236
}
198
237
199
238
private VPack (final Map <Type , VPackSerializer <?>> serializers , final Map <Type , VPackDeserializer <?>> deserializers ,
200
239
final Map <Type , VPackInstanceCreator <?>> instanceCreators , final BuilderOptions builderOptions ,
201
240
final boolean serializeNullValues , final VPackFieldNamingStrategy fieldNamingStrategy ,
202
- final Map <String , Map <Type , VPackDeserializer <?>>> deserializersByName ) {
241
+ final Map <String , Map <Type , VPackDeserializer <?>>> deserializersByName ,
242
+ final Map <Class <? extends Annotation >, VPackAnnotationFieldFilter <? extends Annotation >> annotationFieldFilter ,
243
+ final Map <Class <? extends Annotation >, VPackAnnotationFieldNaming <? extends Annotation >> annotationFieldNaming ) {
203
244
super ();
204
245
this .serializers = serializers ;
205
246
this .deserializers = deserializers ;
@@ -208,7 +249,8 @@ private VPack(final Map<Type, VPackSerializer<?>> serializers, final Map<Type, V
208
249
this .serializeNullValues = serializeNullValues ;
209
250
this .deserializersByName = deserializersByName ;
210
251
keyMapAdapters = new HashMap <Type , VPackKeyMapAdapter <?>>();
211
- cache = new VPackCache (fieldNamingStrategy );
252
+
253
+ cache = new VPackCache (fieldNamingStrategy , annotationFieldFilter , annotationFieldNaming );
212
254
serializationContext = new VPackSerializationContext () {
213
255
@ Override
214
256
public void serialize (final VPackBuilder builder , final String attribute , final Object entity )
0 commit comments