36
36
*/
37
37
@ JacksonStdImpl // since 2.6. NOTE: sub-classes typically are not
38
38
public class BeanPropertyWriter extends PropertyWriter
39
- implements BeanProperty
39
+ implements BeanProperty ,
40
+ java .io .Serializable // since 2.6.2
40
41
{
42
+ // as of 2.6.2
43
+ private static final long serialVersionUID = 4603296144163950020L ;
44
+
41
45
/**
42
46
* Marker object used to indicate "do not serialize if empty"
43
47
*/
@@ -50,54 +54,7 @@ public class BeanPropertyWriter extends PropertyWriter
50
54
* @since 2.6
51
55
*/
52
56
protected final static JsonFormat .Value NO_FORMAT = new JsonFormat .Value ();
53
-
54
- /*
55
- /**********************************************************
56
- /* Settings for accessing property value to serialize
57
- /**********************************************************
58
- */
59
-
60
- /**
61
- * Member (field, method) that represents property and allows access
62
- * to associated annotations.
63
- */
64
- protected final AnnotatedMember _member ;
65
-
66
- /**
67
- * Annotations from context (most often, class that declares property,
68
- * or in case of sub-class serializer, from that sub-class)
69
- */
70
- protected final Annotations _contextAnnotations ;
71
-
72
- /**
73
- * Type property is declared to have, either in class definition
74
- * or associated annotations.
75
- */
76
- protected final JavaType _declaredType ;
77
-
78
- /**
79
- * Accessor method used to get property value, for
80
- * method-accessible properties.
81
- * Null if and only if {@link #_field} is null.
82
- */
83
- protected final Method _accessorMethod ;
84
-
85
- /**
86
- * Field that contains the property value for field-accessible
87
- * properties.
88
- * Null if and only if {@link #_accessorMethod} is null.
89
- */
90
- protected final Field _field ;
91
-
92
- /*
93
- /**********************************************************
94
- /* Opaque internal data that bean serializer factory and
95
- /* bean serializers can add.
96
- /**********************************************************
97
- */
98
57
99
- protected HashMap <Object ,Object > _internalSettings ;
100
-
101
58
/*
102
59
/**********************************************************
103
60
/* Basic property metadata: name, type, other
@@ -122,6 +79,12 @@ public class BeanPropertyWriter extends PropertyWriter
122
79
*/
123
80
protected final PropertyName _wrapperName ;
124
81
82
+ /**
83
+ * Type property is declared to have, either in class definition
84
+ * or associated annotations.
85
+ */
86
+ protected final JavaType _declaredType ;
87
+
125
88
/**
126
89
* Type to use for locating serializer; normally same as return
127
90
* type of the accessor method, but may be overridden by annotations.
@@ -137,6 +100,15 @@ public class BeanPropertyWriter extends PropertyWriter
137
100
*/
138
101
protected JavaType _nonTrivialBaseType ;
139
102
103
+ /**
104
+ * Annotations from context (most often, class that declares property,
105
+ * or in case of sub-class serializer, from that sub-class)
106
+ *<p>
107
+ * NOTE: transient just to support JDK serializability; Annotations
108
+ * do not serialize. At all.
109
+ */
110
+ protected final transient Annotations _contextAnnotations ;
111
+
140
112
/**
141
113
* Additional information about property
142
114
*
@@ -151,6 +123,36 @@ public class BeanPropertyWriter extends PropertyWriter
151
123
*/
152
124
protected transient JsonFormat .Value _format ;
153
125
126
+ /*
127
+ /**********************************************************
128
+ /* Settings for accessing property value to serialize
129
+ /**********************************************************
130
+ */
131
+
132
+ /**
133
+ * Member (field, method) that represents property and allows access
134
+ * to associated annotations.
135
+ */
136
+ protected final AnnotatedMember _member ;
137
+
138
+ /**
139
+ * Accessor method used to get property value, for
140
+ * method-accessible properties.
141
+ * Null if and only if {@link #_field} is null.
142
+ *<p>
143
+ * `transient` (and non-final) only to support JDK serializability.
144
+ */
145
+ protected transient Method _accessorMethod ;
146
+
147
+ /**
148
+ * Field that contains the property value for field-accessible
149
+ * properties.
150
+ * Null if and only if {@link #_accessorMethod} is null.
151
+ *<p>
152
+ * `transient` (and non-final) only to support JDK serializability.
153
+ */
154
+ protected transient Field _field ;
155
+
154
156
/*
155
157
/**********************************************************
156
158
/* Serializers needed
@@ -211,6 +213,15 @@ public class BeanPropertyWriter extends PropertyWriter
211
213
*/
212
214
protected final Class <?>[] _includeInViews ;
213
215
216
+ /*
217
+ /**********************************************************
218
+ /* Opaque internal data that bean serializer factory and
219
+ /* bean serializers can add.
220
+ /**********************************************************
221
+ */
222
+
223
+ protected transient HashMap <Object ,Object > _internalSettings ;
224
+
214
225
/*
215
226
/**********************************************************
216
227
/* Construction, configuration
@@ -301,16 +312,18 @@ protected BeanPropertyWriter(BeanPropertyWriter base, PropertyName name)
301
312
/* 02-Dec-2014, tatu: This is a big mess, alas, what with dependency
302
313
* to MapperConfig to encode, and Afterburner having heartburn
303
314
* for SerializableString (vs SerializedString).
304
- * Hope it can be resolved/reworker in 2.6 timeframe, if not for 2.5
315
+ * Hope it can be resolved/reworked in 2.6 timeframe, if not for 2.5
305
316
*/
306
317
_name = new SerializedString (name .getSimpleName ());
307
318
_wrapperName = base ._wrapperName ;
308
319
309
- _member = base ._member ;
310
320
_contextAnnotations = base ._contextAnnotations ;
311
321
_declaredType = base ._declaredType ;
322
+
323
+ _member = base ._member ;
312
324
_accessorMethod = base ._accessorMethod ;
313
325
_field = base ._field ;
326
+
314
327
_serializer = base ._serializer ;
315
328
_nullSerializer = base ._nullSerializer ;
316
329
// one more thing: copy internal settings, if any (since 1.7)
@@ -421,6 +434,30 @@ public void setNonTrivialBaseType(JavaType t) {
421
434
_nonTrivialBaseType = t ;
422
435
}
423
436
437
+ /*
438
+ /**********************************************************
439
+ /* JDK Serializability
440
+ /**********************************************************
441
+ */
442
+
443
+ /* Ideally would not require mutable state, and instead would re-create with
444
+ * final settings. However, as things are, with sub-types and all, simplest
445
+ * to just change Field/Method value directly.
446
+ */
447
+ Object readResolve () {
448
+ if (_member instanceof AnnotatedField ) {
449
+ _accessorMethod = null ;
450
+ _field = (Field ) _member .getMember ();
451
+ } else if (_member instanceof AnnotatedMethod ) {
452
+ _accessorMethod = (Method ) _member .getMember ();
453
+ _field = null ;
454
+ }
455
+ if (_serializer == null ) {
456
+ _dynamicSerializers = PropertySerializerMap .emptyForProperties ();
457
+ }
458
+ return this ;
459
+ }
460
+
424
461
/*
425
462
/**********************************************************
426
463
/* BeanProperty impl
0 commit comments