4
4
import java .lang .annotation .Annotation ;
5
5
import java .lang .reflect .Constructor ;
6
6
7
- import com .fasterxml .jackson .core .JsonParser ;
8
- import com .fasterxml .jackson .core .JsonProcessingException ;
9
- import com .fasterxml .jackson .core .JsonToken ;
10
- import com .fasterxml .jackson .databind .DeserializationContext ;
11
- import com .fasterxml .jackson .databind .JsonDeserializer ;
12
- import com .fasterxml .jackson .databind .PropertyName ;
7
+ import com .fasterxml .jackson .core .*;
8
+ import com .fasterxml .jackson .databind .*;
13
9
import com .fasterxml .jackson .databind .deser .SettableBeanProperty ;
14
- import com .fasterxml .jackson .databind .introspect .AnnotatedMember ;
10
+ import com .fasterxml .jackson .databind .introspect .* ;
15
11
import com .fasterxml .jackson .databind .util .ClassUtil ;
16
12
17
13
/**
@@ -31,10 +27,17 @@ public final class InnerClassProperty
31
27
protected final SettableBeanProperty _delegate ;
32
28
33
29
/**
34
- * Single-arg constructor we use for value instantiation.
30
+ * Constructor used when deserializing this property.
31
+ * Transient since there is no need to persist; only needed during
32
+ * construction of objects.
35
33
*/
36
- protected final Constructor <?> _creator ;
34
+ final protected transient Constructor <?> _creator ;
37
35
36
+ /**
37
+ * Serializable version of single-arg constructor we use for value instantiation.
38
+ */
39
+ protected AnnotatedConstructor _annotated ;
40
+
38
41
public InnerClassProperty (SettableBeanProperty delegate ,
39
42
Constructor <?> ctor )
40
43
{
@@ -43,6 +46,21 @@ public InnerClassProperty(SettableBeanProperty delegate,
43
46
_creator = ctor ;
44
47
}
45
48
49
+ /**
50
+ * Constructor used with JDK Serialization; needed to handle transient
51
+ * Constructor, wrap/unwrap in/out-of Annotated variant.
52
+ */
53
+ protected InnerClassProperty (InnerClassProperty src , AnnotatedConstructor ann )
54
+ {
55
+ super (src );
56
+ _delegate = src ._delegate ;
57
+ _annotated = ann ;
58
+ _creator = (_annotated == null ) ? null : _annotated .getAnnotated ();
59
+ if (_creator == null ) {
60
+ throw new IllegalArgumentException ("Missing constructor (broken JDK (de)serialization?)" );
61
+ }
62
+ }
63
+
46
64
protected InnerClassProperty (InnerClassProperty src , JsonDeserializer <?> deser )
47
65
{
48
66
super (src , deser );
@@ -82,9 +100,8 @@ public <A extends Annotation> A getAnnotation(Class<A> acls) {
82
100
*/
83
101
84
102
@ Override
85
- public void deserializeAndSet (JsonParser jp , DeserializationContext ctxt ,
86
- Object bean )
87
- throws IOException , JsonProcessingException
103
+ public void deserializeAndSet (JsonParser jp , DeserializationContext ctxt , Object bean )
104
+ throws IOException
88
105
{
89
106
JsonToken t = jp .getCurrentToken ();
90
107
Object value ;
@@ -107,21 +124,37 @@ public void deserializeAndSet(JsonParser jp, DeserializationContext ctxt,
107
124
@ Override
108
125
public Object deserializeSetAndReturn (JsonParser jp ,
109
126
DeserializationContext ctxt , Object instance )
110
- throws IOException , JsonProcessingException
127
+ throws IOException
111
128
{
112
129
return setAndReturn (instance , deserialize (jp , ctxt ));
113
130
}
114
131
115
132
@ Override
116
- public final void set (Object instance , Object value ) throws IOException
117
- {
133
+ public final void set (Object instance , Object value ) throws IOException {
118
134
_delegate .set (instance , value );
119
135
}
120
136
121
137
@ Override
122
- public Object setAndReturn (Object instance , Object value )
123
- throws IOException
124
- {
125
- return _delegate .setAndReturn (instance , value );
138
+ public Object setAndReturn (Object instance , Object value ) throws IOException {
139
+ return _delegate .setAndReturn (instance , value );
140
+ }
141
+
142
+ /*
143
+ /**********************************************************
144
+ /* JDK serialization handling
145
+ /**********************************************************
146
+ */
147
+
148
+ // When reading things back,
149
+ Object readResolve () {
150
+ return new InnerClassProperty (this , _annotated );
151
+ }
152
+
153
+ Object writeReplace () {
154
+ // need to construct a fake instance to support serialization
155
+ if (_annotated != null ) {
156
+ return this ;
157
+ }
158
+ return new InnerClassProperty (this , new AnnotatedConstructor (_creator , null , null ));
126
159
}
127
160
}
0 commit comments