11
11
import com .fasterxml .jackson .annotation .ObjectIdResolver ;
12
12
13
13
import com .fasterxml .jackson .core .*;
14
-
14
+ import com .fasterxml .jackson .core .tree .ArrayTreeNode ;
15
+ import com .fasterxml .jackson .core .tree .ObjectTreeNode ;
15
16
import com .fasterxml .jackson .databind .cfg .ContextAttributes ;
16
17
import com .fasterxml .jackson .databind .deser .*;
17
18
import com .fasterxml .jackson .databind .deser .impl .ObjectIdReader ;
49
50
*/
50
51
public abstract class DeserializationContext
51
52
extends DatabindContext
52
- implements java .io .Serializable
53
+ implements java .io .Serializable ,
54
+ ObjectReadContext // 3.0
53
55
{
54
56
private static final long serialVersionUID = 3L ;
55
57
@@ -100,18 +102,29 @@ public abstract class DeserializationContext
100
102
protected final Class <?> _view ;
101
103
102
104
/**
103
- * Currently active parser used for deserialization.
104
- * May be different from the outermost parser
105
- * when content is buffered.
105
+ * Schema for underlying parser to use, if any.
106
106
*/
107
- protected transient JsonParser _parser ;
108
-
107
+ protected final FormatSchema _schema ;
108
+
109
109
/**
110
110
* Object used for resolving references to injectable
111
111
* values.
112
112
*/
113
113
protected final InjectableValues _injectableValues ;
114
+
115
+ /*
116
+ /**********************************************************
117
+ /* State (not for blueprints)
118
+ /**********************************************************
119
+ */
114
120
121
+ /**
122
+ * Currently active parser used for deserialization.
123
+ * May be different from the outermost parser
124
+ * when content is buffered.
125
+ */
126
+ protected transient JsonParser _parser ;
127
+
115
128
/*
116
129
/**********************************************************
117
130
/* Per-operation reusable helper objects (not for blueprints)
@@ -126,17 +139,13 @@ public abstract class DeserializationContext
126
139
127
140
/**
128
141
* Lazily-constructed holder for per-call attributes.
129
- *
130
- * @since 2.3
131
142
*/
132
143
protected transient ContextAttributes _attributes ;
133
144
134
145
/**
135
146
* Type of {@link JsonDeserializer} (or, more specifically,
136
147
* {@link ContextualDeserializer}) that is being
137
148
* contextualized currently.
138
- *
139
- * @since 2.5
140
149
*/
141
150
protected LinkedNode <JavaType > _currentType ;
142
151
@@ -166,6 +175,7 @@ protected DeserializationContext(DeserializerFactory df,
166
175
_injectableValues = null ;
167
176
_view = null ;
168
177
_attributes = null ;
178
+ _schema = null ;
169
179
}
170
180
171
181
protected DeserializationContext (DeserializationContext src ,
@@ -177,7 +187,7 @@ protected DeserializationContext(DeserializationContext src,
177
187
_config = src ._config ;
178
188
_featureFlags = src ._featureFlags ;
179
189
_view = src ._view ;
180
- _parser = src ._parser ;
190
+ _schema = src ._schema ;
181
191
_injectableValues = src ._injectableValues ;
182
192
_attributes = src ._attributes ;
183
193
}
@@ -186,7 +196,7 @@ protected DeserializationContext(DeserializationContext src,
186
196
* Constructor used for creating actual per-call instances.
187
197
*/
188
198
protected DeserializationContext (DeserializationContext src ,
189
- DeserializationConfig config , JsonParser p ,
199
+ DeserializationConfig config , FormatSchema schema ,
190
200
InjectableValues injectableValues )
191
201
{
192
202
_cache = src ._cache ;
@@ -195,7 +205,8 @@ protected DeserializationContext(DeserializationContext src,
195
205
_config = config ;
196
206
_featureFlags = config .getDeserializationFeatures ();
197
207
_view = config .getActiveView ();
198
- _parser = p ;
208
+ _schema = schema ;
209
+
199
210
_injectableValues = injectableValues ;
200
211
_attributes = config .getAttributes ();
201
212
}
@@ -210,6 +221,8 @@ protected DeserializationContext(DeserializationContext src) {
210
221
_config = src ._config ;
211
222
_featureFlags = src ._featureFlags ;
212
223
_view = src ._view ;
224
+ _schema = src ._schema ;
225
+
213
226
_injectableValues = null ;
214
227
}
215
228
@@ -274,7 +287,7 @@ public TimeZone getTimeZone() {
274
287
275
288
/*
276
289
/**********************************************************
277
- /* Access to per-call state, like generic attributes (2.3+)
290
+ /* Access to per-call state, like generic attributes
278
291
/**********************************************************
279
292
*/
280
293
@@ -297,8 +310,6 @@ public DeserializationContext setAttribute(Object key, Object value)
297
310
* do not get passed (or do not retain) type information when being
298
311
* constructed: happens for example for deserializers constructed
299
312
* from annotations.
300
- *
301
- * @since 2.5
302
313
*
303
314
* @return Type of {@link ContextualDeserializer} being contextualized,
304
315
* if process is on-going; null if not.
@@ -307,6 +318,37 @@ public JavaType getContextualType() {
307
318
return (_currentType == null ) ? null : _currentType .value ();
308
319
}
309
320
321
+ /*
322
+ /**********************************************************
323
+ /* ObjectReadContext implementation
324
+ /**********************************************************
325
+ */
326
+
327
+ @ Override
328
+ public FormatSchema getSchema () {
329
+ return _schema ;
330
+ }
331
+
332
+ @ Override
333
+ public int getParserFeatures (int defaults ) {
334
+ return _config .getParserFeatures (defaults );
335
+ }
336
+
337
+ @ Override
338
+ public int getFormatReadFeatures (int defaults ) {
339
+ return _config .getFormatReadFeatures (defaults );
340
+ }
341
+
342
+ @ Override
343
+ public ArrayTreeNode createArrayNode () {
344
+ return getNodeFactory ().arrayNode ();
345
+ }
346
+
347
+ @ Override
348
+ public ObjectTreeNode createObjectNode () {
349
+ return getNodeFactory ().objectNode ();
350
+ }
351
+
310
352
/*
311
353
/**********************************************************
312
354
/* Public API, config setting accessors
@@ -1454,8 +1496,8 @@ public JsonMappingException wrongTokenException(JsonParser p, JavaType targetTyp
1454
1496
public JsonMappingException wrongTokenException (JsonParser p , Class <?> targetType ,
1455
1497
JsonToken expToken , String extra )
1456
1498
{
1457
- String msg = String . format ( "Unexpected token (%s), expected %s" ,
1458
- p . currentToken () , expToken );
1499
+ JsonToken t = ( p == null ) ? null : p . currentToken ();
1500
+ String msg = String . format ( "Unexpected token (%s), expected %s" , t , expToken );
1459
1501
msg = _colonConcat (msg , extra );
1460
1502
return MismatchedInputException .from (p , targetType , msg );
1461
1503
}
0 commit comments