Skip to content

Commit be5b5df

Browse files
committed
Start updating databind to pass ObjectReadContext too -- couple of transient test failures now
1 parent e3eb018 commit be5b5df

File tree

9 files changed

+382
-282
lines changed

9 files changed

+382
-282
lines changed

src/main/java/com/fasterxml/jackson/databind/DeserializationConfig.java

Lines changed: 12 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
*/
2323
public final class DeserializationConfig
2424
extends MapperConfigBase<DeserializationFeature, DeserializationConfig>
25-
implements java.io.Serializable // since 2.1
25+
implements java.io.Serializable
2626
{
2727
private static final long serialVersionUID = 2;
2828

@@ -389,8 +389,6 @@ public DeserializationConfig withoutFeatures(DeserializationFeature... features)
389389
/**
390390
* Fluent factory method that will construct and return a new configuration
391391
* object instance with specified features enabled.
392-
*
393-
* @since 2.5
394392
*/
395393
public DeserializationConfig with(JsonParser.Feature feature)
396394
{
@@ -405,8 +403,6 @@ public DeserializationConfig with(JsonParser.Feature feature)
405403
/**
406404
* Fluent factory method that will construct and return a new configuration
407405
* object instance with specified features enabled.
408-
*
409-
* @since 2.5
410406
*/
411407
public DeserializationConfig withFeatures(JsonParser.Feature... features)
412408
{
@@ -426,8 +422,6 @@ public DeserializationConfig withFeatures(JsonParser.Feature... features)
426422
/**
427423
* Fluent factory method that will construct and return a new configuration
428424
* object instance with specified feature disabled.
429-
*
430-
* @since 2.5
431425
*/
432426
public DeserializationConfig without(JsonParser.Feature feature)
433427
{
@@ -469,8 +463,6 @@ public DeserializationConfig withoutFeatures(JsonParser.Feature... features)
469463
/**
470464
* Fluent factory method that will construct and return a new configuration
471465
* object instance with specified features enabled.
472-
*
473-
* @since 2.7
474466
*/
475467
public DeserializationConfig with(FormatFeature feature)
476468
{
@@ -485,8 +477,6 @@ public DeserializationConfig with(FormatFeature feature)
485477
/**
486478
* Fluent factory method that will construct and return a new configuration
487479
* object instance with specified features enabled.
488-
*
489-
* @since 2.7
490480
*/
491481
public DeserializationConfig withFeatures(FormatFeature... features)
492482
{
@@ -570,24 +560,22 @@ public DeserializationConfig withNoProblemHandlers() {
570560

571561
/*
572562
/**********************************************************
573-
/* JsonParser initialization
563+
/* Support for ObjectReadContext
574564
/**********************************************************
575565
*/
576566

577567
/**
578-
* Method called by {@link ObjectMapper} and {@link ObjectReader}
579-
* to modify those {@link com.fasterxml.jackson.core.JsonParser.Feature} settings
580-
* that have been configured via this config instance.
581-
*
582-
* @since 2.5
568+
* @since 3.0
583569
*/
584-
public void initialize(JsonParser p) {
585-
if (_parserFeaturesToChange != 0) {
586-
p.overrideStdFeatures(_parserFeatures, _parserFeaturesToChange);
587-
}
588-
if (_formatReadFeaturesToChange != 0) {
589-
p.overrideFormatFeatures(_formatReadFeatures, _formatReadFeaturesToChange);
590-
}
570+
public int getParserFeatures(int defaults) {
571+
return (defaults & ~_parserFeaturesToChange) | _parserFeatures;
572+
}
573+
574+
/**
575+
* @since 3.0
576+
*/
577+
public int getFormatReadFeatures(int defaults) {
578+
return (defaults & ~_formatReadFeaturesToChange) | _formatReadFeatures;
591579
}
592580

593581
/*

src/main/java/com/fasterxml/jackson/databind/DeserializationContext.java

Lines changed: 61 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
import com.fasterxml.jackson.annotation.ObjectIdResolver;
1212

1313
import com.fasterxml.jackson.core.*;
14-
14+
import com.fasterxml.jackson.core.tree.ArrayTreeNode;
15+
import com.fasterxml.jackson.core.tree.ObjectTreeNode;
1516
import com.fasterxml.jackson.databind.cfg.ContextAttributes;
1617
import com.fasterxml.jackson.databind.deser.*;
1718
import com.fasterxml.jackson.databind.deser.impl.ObjectIdReader;
@@ -49,7 +50,8 @@
4950
*/
5051
public abstract class DeserializationContext
5152
extends DatabindContext
52-
implements java.io.Serializable
53+
implements java.io.Serializable,
54+
ObjectReadContext // 3.0
5355
{
5456
private static final long serialVersionUID = 3L;
5557

@@ -100,18 +102,29 @@ public abstract class DeserializationContext
100102
protected final Class<?> _view;
101103

102104
/**
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.
106106
*/
107-
protected transient JsonParser _parser;
108-
107+
protected final FormatSchema _schema;
108+
109109
/**
110110
* Object used for resolving references to injectable
111111
* values.
112112
*/
113113
protected final InjectableValues _injectableValues;
114+
115+
/*
116+
/**********************************************************
117+
/* State (not for blueprints)
118+
/**********************************************************
119+
*/
114120

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+
115128
/*
116129
/**********************************************************
117130
/* Per-operation reusable helper objects (not for blueprints)
@@ -126,17 +139,13 @@ public abstract class DeserializationContext
126139

127140
/**
128141
* Lazily-constructed holder for per-call attributes.
129-
*
130-
* @since 2.3
131142
*/
132143
protected transient ContextAttributes _attributes;
133144

134145
/**
135146
* Type of {@link JsonDeserializer} (or, more specifically,
136147
* {@link ContextualDeserializer}) that is being
137148
* contextualized currently.
138-
*
139-
* @since 2.5
140149
*/
141150
protected LinkedNode<JavaType> _currentType;
142151

@@ -166,6 +175,7 @@ protected DeserializationContext(DeserializerFactory df,
166175
_injectableValues = null;
167176
_view = null;
168177
_attributes = null;
178+
_schema = null;
169179
}
170180

171181
protected DeserializationContext(DeserializationContext src,
@@ -177,7 +187,7 @@ protected DeserializationContext(DeserializationContext src,
177187
_config = src._config;
178188
_featureFlags = src._featureFlags;
179189
_view = src._view;
180-
_parser = src._parser;
190+
_schema = src._schema;
181191
_injectableValues = src._injectableValues;
182192
_attributes = src._attributes;
183193
}
@@ -186,7 +196,7 @@ protected DeserializationContext(DeserializationContext src,
186196
* Constructor used for creating actual per-call instances.
187197
*/
188198
protected DeserializationContext(DeserializationContext src,
189-
DeserializationConfig config, JsonParser p,
199+
DeserializationConfig config, FormatSchema schema,
190200
InjectableValues injectableValues)
191201
{
192202
_cache = src._cache;
@@ -195,7 +205,8 @@ protected DeserializationContext(DeserializationContext src,
195205
_config = config;
196206
_featureFlags = config.getDeserializationFeatures();
197207
_view = config.getActiveView();
198-
_parser = p;
208+
_schema = schema;
209+
199210
_injectableValues = injectableValues;
200211
_attributes = config.getAttributes();
201212
}
@@ -210,6 +221,8 @@ protected DeserializationContext(DeserializationContext src) {
210221
_config = src._config;
211222
_featureFlags = src._featureFlags;
212223
_view = src._view;
224+
_schema = src._schema;
225+
213226
_injectableValues = null;
214227
}
215228

@@ -274,7 +287,7 @@ public TimeZone getTimeZone() {
274287

275288
/*
276289
/**********************************************************
277-
/* Access to per-call state, like generic attributes (2.3+)
290+
/* Access to per-call state, like generic attributes
278291
/**********************************************************
279292
*/
280293

@@ -297,8 +310,6 @@ public DeserializationContext setAttribute(Object key, Object value)
297310
* do not get passed (or do not retain) type information when being
298311
* constructed: happens for example for deserializers constructed
299312
* from annotations.
300-
*
301-
* @since 2.5
302313
*
303314
* @return Type of {@link ContextualDeserializer} being contextualized,
304315
* if process is on-going; null if not.
@@ -307,6 +318,37 @@ public JavaType getContextualType() {
307318
return (_currentType == null) ? null : _currentType.value();
308319
}
309320

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+
310352
/*
311353
/**********************************************************
312354
/* Public API, config setting accessors
@@ -1454,8 +1496,8 @@ public JsonMappingException wrongTokenException(JsonParser p, JavaType targetTyp
14541496
public JsonMappingException wrongTokenException(JsonParser p, Class<?> targetType,
14551497
JsonToken expToken, String extra)
14561498
{
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);
14591501
msg = _colonConcat(msg, extra);
14601502
return MismatchedInputException.from(p, targetType, msg);
14611503
}

0 commit comments

Comments
 (0)