1 package com.fasterxml.jackson.databind;
2
3 import java.util.*;
4
5 import com.fasterxml.jackson.core.*;
6 import com.fasterxml.jackson.core.json.JsonReadFeature;
7 import com.fasterxml.jackson.databind.cfg.*;
8 import com.fasterxml.jackson.databind.deser.DeserializationProblemHandler;
9 import com.fasterxml.jackson.databind.introspect.*;
10 import com.fasterxml.jackson.databind.jsontype.*;
11 import com.fasterxml.jackson.databind.node.JsonNodeFactory;
12 import com.fasterxml.jackson.databind.util.LinkedNode;
13 import com.fasterxml.jackson.databind.util.RootNameLookup;
14
15 /**
16  * Object that contains baseline configuration for deserialization
17  * process. An instance is owned by {@link ObjectMapper}, which
18  * passes an immutable instance to be used for deserialization process.
19  *<p>
20  * Note that instances are considered immutable and as such no copies
21  * should need to be created for sharing; all copying is done with
22  * "fluent factory" methods.
23  */

24 public final class DeserializationConfig
25     extends MapperConfigBase<DeserializationFeature, DeserializationConfig>
26     implements java.io.Serializable // since 2.1
27 {
28     // since 2.9
29     private static final long serialVersionUID = 2;
30
31     // since 2.10.1
32     private final static int DESER_FEATURE_DEFAULTS = collectFeatureDefaults(DeserializationFeature.class);
33
34     /*
35     /**********************************************************
36     /* Configured helper objects
37     /**********************************************************
38      */

39
40     /**
41      * Linked list that contains all registered problem handlers.
42      * Implementation as front-added linked list allows for sharing
43      * of the list (tail) without copying the list.
44      */

45     protected final LinkedNode<DeserializationProblemHandler> _problemHandlers;
46
47     /**
48      * Factory used for constructing {@link com.fasterxml.jackson.databind.JsonNode} instances.
49      */

50     protected final JsonNodeFactory _nodeFactory;
51
52     /*
53     /**********************************************************
54     /* Deserialization features 
55     /**********************************************************
56      */

57
58     /**
59      * Set of {@link DeserializationFeature}s enabled.
60      */

61     protected final int _deserFeatures;
62
63     /*
64     /**********************************************************
65     /* Parser features: generic, format-specific
66     /**********************************************************
67      */

68
69     /**
70      * States of {@link com.fasterxml.jackson.core.JsonParser.Feature}s to enable/disable.
71      */

72     protected final int _parserFeatures;
73
74     /**
75      * Bitflag of {@link com.fasterxml.jackson.core.JsonParser.Feature}s to enable/disable
76      */

77     protected final int _parserFeaturesToChange;
78
79     /**
80      * States of {@link com.fasterxml.jackson.core.FormatFeature}s to enable/disable.
81      *
82      * @since 2.7
83      */

84     protected final int _formatReadFeatures;
85
86     /**
87      * Bitflag of {@link com.fasterxml.jackson.core.FormatFeature}s to enable/disable
88      *
89      * @since 2.7
90      */

91     protected final int _formatReadFeaturesToChange;
92
93     /*
94     /**********************************************************
95     /* Life-cycle, primary constructors for new instances
96     /**********************************************************
97      */

98
99     /**
100      * Constructor used by ObjectMapper to create default configuration object instance.
101      */

102     public DeserializationConfig(BaseSettings base,
103             SubtypeResolver str, SimpleMixInResolver mixins, RootNameLookup rootNames,
104             ConfigOverrides configOverrides)
105     {
106         super(base, str, mixins, rootNames, configOverrides);
107         _deserFeatures = DESER_FEATURE_DEFAULTS;
108         _nodeFactory = JsonNodeFactory.instance;
109         _problemHandlers = null;
110         _parserFeatures = 0;
111         _parserFeaturesToChange = 0;
112         _formatReadFeatures = 0;
113         _formatReadFeaturesToChange = 0;
114     }
115
116     /**
117      * Copy-constructor used for making a copy used by new {@link ObjectMapper}.
118      *
119      * @since 2.11.2
120      */

121     protected DeserializationConfig(DeserializationConfig src,
122             SubtypeResolver str, SimpleMixInResolver mixins, RootNameLookup rootNames,
123             ConfigOverrides configOverrides)
124     {
125         super(src, str, mixins, rootNames, configOverrides);
126         _deserFeatures = src._deserFeatures;
127         _problemHandlers = src._problemHandlers;
128         _nodeFactory = src._nodeFactory;
129         _parserFeatures = src._parserFeatures;
130         _parserFeaturesToChange = src._parserFeaturesToChange;
131         _formatReadFeatures = src._formatReadFeatures;
132         _formatReadFeaturesToChange = src._formatReadFeaturesToChange;
133     }
134
135     /**
136      * @since 2.9
137      * @deprecated since 2.11.2
138      */

139     @Deprecated
140     protected DeserializationConfig(DeserializationConfig src,
141             SimpleMixInResolver mixins, RootNameLookup rootNames,
142             ConfigOverrides configOverrides)
143     {
144         this(src, src._subtypeResolver, mixins, rootNames, configOverrides);
145     }
146
147     /*
148     /**********************************************************
149     /* Life-cycle, secondary constructors to support
150     /* "mutant factories", with single property changes
151     /**********************************************************
152      */

153
154     private DeserializationConfig(DeserializationConfig src,
155             int mapperFeatures, int deserFeatures,
156             int parserFeatures, int parserFeatureMask,
157             int formatFeatures, int formatFeatureMask)
158     {
159         super(src, mapperFeatures);
160         _deserFeatures = deserFeatures;
161         _nodeFactory = src._nodeFactory;
162         _problemHandlers = src._problemHandlers;
163         _parserFeatures = parserFeatures;
164         _parserFeaturesToChange = parserFeatureMask;
165         _formatReadFeatures = formatFeatures;
166         _formatReadFeaturesToChange = formatFeatureMask;
167     }
168     
169     /**
170      * Copy constructor used to create a non-shared instance with given mix-in
171      * annotation definitions and subtype resolver.
172      */

173     private DeserializationConfig(DeserializationConfig src, SubtypeResolver str)
174     {
175         super(src, str);
176         _deserFeatures = src._deserFeatures;
177         _nodeFactory = src._nodeFactory;
178         _problemHandlers = src._problemHandlers;
179         _parserFeatures = src._parserFeatures;
180         _parserFeaturesToChange = src._parserFeaturesToChange;
181         _formatReadFeatures = src._formatReadFeatures;
182         _formatReadFeaturesToChange = src._formatReadFeaturesToChange;
183     }
184
185     private DeserializationConfig(DeserializationConfig src, BaseSettings base)
186     {
187         super(src, base);
188         _deserFeatures = src._deserFeatures;
189         _nodeFactory = src._nodeFactory;
190         _problemHandlers = src._problemHandlers;
191         _parserFeatures = src._parserFeatures;
192         _parserFeaturesToChange = src._parserFeaturesToChange;
193         _formatReadFeatures = src._formatReadFeatures;
194         _formatReadFeaturesToChange = src._formatReadFeaturesToChange;
195     }
196     
197     private DeserializationConfig(DeserializationConfig src, JsonNodeFactory f)
198     {
199         super(src);
200         _deserFeatures = src._deserFeatures;
201         _problemHandlers = src._problemHandlers;
202         _nodeFactory = f;
203         _parserFeatures = src._parserFeatures;
204         _parserFeaturesToChange = src._parserFeaturesToChange;
205         _formatReadFeatures = src._formatReadFeatures;
206         _formatReadFeaturesToChange = src._formatReadFeaturesToChange;
207     }
208
209     private DeserializationConfig(DeserializationConfig src,
210             LinkedNode<DeserializationProblemHandler> problemHandlers)
211     {
212         super(src);
213         _deserFeatures = src._deserFeatures;
214         _problemHandlers = problemHandlers;
215         _nodeFactory = src._nodeFactory;
216         _parserFeatures = src._parserFeatures;
217         _parserFeaturesToChange = src._parserFeaturesToChange;
218         _formatReadFeatures = src._formatReadFeatures;
219         _formatReadFeaturesToChange = src._formatReadFeaturesToChange;
220     }
221
222     private DeserializationConfig(DeserializationConfig src, PropertyName rootName)
223     {
224         super(src, rootName);
225         _deserFeatures = src._deserFeatures;
226         _problemHandlers = src._problemHandlers;
227         _nodeFactory = src._nodeFactory;
228         _parserFeatures = src._parserFeatures;
229         _parserFeaturesToChange = src._parserFeaturesToChange;
230         _formatReadFeatures = src._formatReadFeatures;
231         _formatReadFeaturesToChange = src._formatReadFeaturesToChange;
232     }
233
234     private DeserializationConfig(DeserializationConfig src, Class<?> view)
235     {
236         super(src, view);
237         _deserFeatures = src._deserFeatures;
238         _problemHandlers = src._problemHandlers;
239         _nodeFactory = src._nodeFactory;
240         _parserFeatures = src._parserFeatures;
241         _parserFeaturesToChange = src._parserFeaturesToChange;
242         _formatReadFeatures = src._formatReadFeatures;
243         _formatReadFeaturesToChange = src._formatReadFeaturesToChange;
244     }
245
246     protected DeserializationConfig(DeserializationConfig src, ContextAttributes attrs)
247     {
248         super(src, attrs);
249         _deserFeatures = src._deserFeatures;
250         _problemHandlers = src._problemHandlers;
251         _nodeFactory = src._nodeFactory;
252         _parserFeatures = src._parserFeatures;
253         _parserFeaturesToChange = src._parserFeaturesToChange;
254         _formatReadFeatures = src._formatReadFeatures;
255         _formatReadFeaturesToChange = src._formatReadFeaturesToChange;
256     }
257
258     protected DeserializationConfig(DeserializationConfig src, SimpleMixInResolver mixins)
259     {
260         super(src, mixins);
261         _deserFeatures = src._deserFeatures;
262         _problemHandlers = src._problemHandlers;
263         _nodeFactory = src._nodeFactory;
264         _parserFeatures = src._parserFeatures;
265         _parserFeaturesToChange = src._parserFeaturesToChange;
266         _formatReadFeatures = src._formatReadFeatures;
267         _formatReadFeaturesToChange = src._formatReadFeaturesToChange;
268     }
269
270     // for unit tests only:
271     protected BaseSettings getBaseSettings() { return _base; }
272
273     /*
274     /**********************************************************
275     /* Life-cycle, general factory methods from MapperConfig(Base)
276     /**********************************************************
277      */

278
279     @Override // since 2.9
280     protected final DeserializationConfig _withBase(BaseSettings newBase) {
281         return (_base == newBase) ? this : new DeserializationConfig(this, newBase);
282     }
283
284     @Override // since 2.9
285     protected final DeserializationConfig _withMapperFeatures(int mapperFeatures) {
286         return new DeserializationConfig(this, mapperFeatures, _deserFeatures,
287                         _parserFeatures, _parserFeaturesToChange,
288                         _formatReadFeatures, _formatReadFeaturesToChange);
289     }
290
291     /*
292     /**********************************************************
293     /* Life-cycle, specific factory methods from MapperConfig
294     /**********************************************************
295      */

296
297     @Override
298     public DeserializationConfig with(SubtypeResolver str) {
299         return (_subtypeResolver == str) ? this : new DeserializationConfig(this, str);
300     }
301
302     @Override
303     public DeserializationConfig withRootName(PropertyName rootName) {
304         if (rootName == null) {
305             if (_rootName == null) {
306                 return this;
307             }
308         } else if (rootName.equals(_rootName)) {
309             return this;
310         }
311         return new DeserializationConfig(this, rootName);
312     }
313
314     @Override
315     public DeserializationConfig withView(Class<?> view) {
316         return (_view == view) ? this : new DeserializationConfig(this, view);
317     }
318
319     @Override
320     public DeserializationConfig with(ContextAttributes attrs) {
321         return (attrs == _attributes) ? this : new DeserializationConfig(this, attrs);
322     }
323
324     /*
325     /**********************************************************
326     /* Life-cycle, DeserializationFeature-based factory methods
327     /**********************************************************
328      */

329
330     /**
331      * Fluent factory method that will construct and return a new configuration
332      * object instance with specified features enabled.
333      */

334     public DeserializationConfig with(DeserializationFeature feature)
335     {
336         int newDeserFeatures = (_deserFeatures | feature.getMask());
337         return (newDeserFeatures == _deserFeatures) ? this :
338             new DeserializationConfig(this, _mapperFeatures, newDeserFeatures,
339                     _parserFeatures, _parserFeaturesToChange,
340                     _formatReadFeatures, _formatReadFeaturesToChange);
341     }
342
343     /**
344      * Fluent factory method that will construct and return a new configuration
345      * object instance with specified features enabled.
346      */

347     public DeserializationConfig with(DeserializationFeature first,
348             DeserializationFeature... features)
349     {
350         int newDeserFeatures = _deserFeatures | first.getMask();
351         for (DeserializationFeature f : features) {
352             newDeserFeatures |= f.getMask();
353         }
354         return (newDeserFeatures == _deserFeatures) ? this :
355             new DeserializationConfig(this, _mapperFeatures, newDeserFeatures,
356                     _parserFeatures, _parserFeaturesToChange,
357                     _formatReadFeatures, _formatReadFeaturesToChange);
358     }
359
360     /**
361      * Fluent factory method that will construct and return a new configuration
362      * object instance with specified features enabled.
363      */

364     public DeserializationConfig withFeatures(DeserializationFeature... features)
365     {
366         int newDeserFeatures = _deserFeatures;
367         for (DeserializationFeature f : features) {
368             newDeserFeatures |= f.getMask();
369         }
370         return (newDeserFeatures == _deserFeatures) ? this :
371             new DeserializationConfig(this, _mapperFeatures, newDeserFeatures,
372                     _parserFeatures, _parserFeaturesToChange,
373                     _formatReadFeatures, _formatReadFeaturesToChange);
374     }
375     
376     /**
377      * Fluent factory method that will construct and return a new configuration
378      * object instance with specified feature disabled.
379      */

380     public DeserializationConfig without(DeserializationFeature feature)
381     {
382         int newDeserFeatures = _deserFeatures & ~feature.getMask();
383         return (newDeserFeatures == _deserFeatures) ? this :
384             new DeserializationConfig(this, _mapperFeatures, newDeserFeatures,
385                     _parserFeatures, _parserFeaturesToChange,
386                     _formatReadFeatures, _formatReadFeaturesToChange);
387     }
388
389     /**
390      * Fluent factory method that will construct and return a new configuration
391      * object instance with specified features disabled.
392      */

393     public DeserializationConfig without(DeserializationFeature first,
394             DeserializationFeature... features)
395     {
396         int newDeserFeatures = _deserFeatures & ~first.getMask();
397         for (DeserializationFeature f : features) {
398             newDeserFeatures &= ~f.getMask();
399         }
400         return (newDeserFeatures == _deserFeatures) ? this :
401             new DeserializationConfig(this, _mapperFeatures, newDeserFeatures,
402                     _parserFeatures, _parserFeaturesToChange,
403                     _formatReadFeatures, _formatReadFeaturesToChange);
404     }
405
406     /**
407      * Fluent factory method that will construct and return a new configuration
408      * object instance with specified features disabled.
409      */

410     public DeserializationConfig withoutFeatures(DeserializationFeature... features)
411     {
412         int newDeserFeatures = _deserFeatures;
413         for (DeserializationFeature f : features) {
414             newDeserFeatures &= ~f.getMask();
415         }
416         return (newDeserFeatures == _deserFeatures) ? this :
417             new DeserializationConfig(this, _mapperFeatures, newDeserFeatures,
418                     _parserFeatures, _parserFeaturesToChange,
419                     _formatReadFeatures, _formatReadFeaturesToChange);
420     }
421
422     /*
423     /**********************************************************
424     /* Life-cycle, JsonParser.Feature-based factory methods
425     /**********************************************************
426      */

427
428     /**
429      * Fluent factory method that will construct and return a new configuration
430      * object instance with specified features enabled.
431      *
432      * @since 2.5
433      */

434     public DeserializationConfig with(JsonParser.Feature feature)
435     {
436         int newSet = _parserFeatures | feature.getMask();
437         int newMask = _parserFeaturesToChange | feature.getMask();
438         return ((_parserFeatures == newSet) && (_parserFeaturesToChange == newMask)) ? this :
439             new DeserializationConfig(this,  _mapperFeatures, _deserFeatures,
440                     newSet, newMask,
441                     _formatReadFeatures, _formatReadFeaturesToChange);
442     }
443
444     /**
445      * Fluent factory method that will construct and return a new configuration
446      * object instance with specified features enabled.
447      *
448      * @since 2.5
449      */

450     public DeserializationConfig withFeatures(JsonParser.Feature... features)
451     {
452         int newSet = _parserFeatures;
453         int newMask = _parserFeaturesToChange;
454         for (JsonParser.Feature f : features) {
455             int mask = f.getMask();
456             newSet |= mask;
457             newMask |= mask;
458         }
459         return ((_parserFeatures == newSet) && (_parserFeaturesToChange == newMask)) ? this :
460             new DeserializationConfig(this,  _mapperFeatures, _deserFeatures,
461                     newSet, newMask,
462                     _formatReadFeatures, _formatReadFeaturesToChange);
463     }
464     
465     /**
466      * Fluent factory method that will construct and return a new configuration
467      * object instance with specified feature disabled.
468      *
469      * @since 2.5
470      */

471     public DeserializationConfig without(JsonParser.Feature feature)
472     {
473         int newSet = _parserFeatures & ~feature.getMask();
474         int newMask = _parserFeaturesToChange | feature.getMask();
475         return ((_parserFeatures == newSet) && (_parserFeaturesToChange == newMask)) ? this :
476             new DeserializationConfig(this,  _mapperFeatures, _deserFeatures,
477                     newSet, newMask,
478                     _formatReadFeatures, _formatReadFeaturesToChange);
479     }
480
481     /**
482      * Fluent factory method that will construct and return a new configuration
483      * object instance with specified features disabled.
484      *
485      * @since 2.5
486      */

487     public DeserializationConfig withoutFeatures(JsonParser.Feature... features)
488     {
489         int newSet = _parserFeatures;
490         int newMask = _parserFeaturesToChange;
491         for (JsonParser.Feature f : features) {
492             int mask = f.getMask();
493             newSet &= ~mask;
494             newMask |= mask;
495         }
496         return ((_parserFeatures == newSet) && (_parserFeaturesToChange == newMask)) ? this :
497             new DeserializationConfig(this,  _mapperFeatures, _deserFeatures,
498                     newSet, newMask,
499                     _formatReadFeatures, _formatReadFeaturesToChange);
500     }
501
502     /*
503     /**********************************************************
504     /* Life-cycle, JsonParser.FormatFeature-based factory methods
505     /**********************************************************
506      */

507
508     /**
509      * Fluent factory method that will construct and return a new configuration
510      * object instance with specified features enabled.
511      *
512      * @since 2.7
513      */

514     public DeserializationConfig with(FormatFeature feature)
515     {
516         // 08-Oct-2018, tatu: Alas, complexity due to newly (2.10) refactored json-features:
517         if (feature instanceof JsonReadFeature) {
518             return _withJsonReadFeatures(feature);
519         }
520         int newSet = _formatReadFeatures | feature.getMask();
521         int newMask = _formatReadFeaturesToChange | feature.getMask();
522         return ((_formatReadFeatures == newSet) && (_formatReadFeaturesToChange == newMask)) ? this :
523             new DeserializationConfig(this,  _mapperFeatures, _deserFeatures,
524                     _parserFeatures, _parserFeaturesToChange,
525                     newSet, newMask);
526     }
527
528     /**
529      * Fluent factory method that will construct and return a new configuration
530      * object instance with specified features enabled.
531      *
532      * @since 2.7
533      */

534     public DeserializationConfig withFeatures(FormatFeature... features)
535     {
536         // 08-Oct-2018, tatu: Alas, complexity due to newly (2.10) refactored json-features:
537         if (features.length > 0 && (features[0] instanceof JsonReadFeature)) {
538             return _withJsonReadFeatures(features);
539         }
540         int newSet = _formatReadFeatures;
541         int newMask = _formatReadFeaturesToChange;
542         for (FormatFeature f : features) {
543             int mask = f.getMask();
544             newSet |= mask;
545             newMask |= mask;
546         }
547         return ((_formatReadFeatures == newSet) && (_formatReadFeaturesToChange == newMask)) ? this :
548             new DeserializationConfig(this,  _mapperFeatures, _deserFeatures,
549                     _parserFeatures, _parserFeaturesToChange,
550                     newSet, newMask);
551     }
552     
553     /**
554      * Fluent factory method that will construct and return a new configuration
555      * object instance with specified feature disabled.
556      *
557      * @since 2.7
558      */

559     public DeserializationConfig without(FormatFeature feature)
560     {
561         // 08-Oct-2018, tatu: Alas, complexity due to newly (2.10) refactored json-features:
562         if (feature instanceof JsonReadFeature) {
563             return _withoutJsonReadFeatures(feature);
564         }
565         int newSet = _formatReadFeatures & ~feature.getMask();
566         int newMask = _formatReadFeaturesToChange | feature.getMask();
567         return ((_formatReadFeatures == newSet) && (_formatReadFeaturesToChange == newMask)) ? this :
568             new DeserializationConfig(this,  _mapperFeatures, _deserFeatures,
569                     _parserFeatures, _parserFeaturesToChange,
570                     newSet, newMask);
571     }
572
573     /**
574      * Fluent factory method that will construct and return a new configuration
575      * object instance with specified features disabled.
576      *
577      * @since 2.7
578      */

579     public DeserializationConfig withoutFeatures(FormatFeature... features)
580     {
581         // 08-Oct-2018, tatu: Alas, complexity due to newly (2.10) refactored json-features:
582         if (features.length > 0 && (features[0] instanceof JsonReadFeature)) {
583             return _withoutJsonReadFeatures(features);
584         }
585         int newSet = _formatReadFeatures;
586         int newMask = _formatReadFeaturesToChange;
587         for (FormatFeature f : features) {
588             int mask = f.getMask();
589             newSet &= ~mask;
590             newMask |= mask;
591         }
592         return ((_formatReadFeatures == newSet) && (_formatReadFeaturesToChange == newMask)) ? this :
593             new DeserializationConfig(this,  _mapperFeatures, _deserFeatures,
594                     _parserFeatures, _parserFeaturesToChange,
595                     newSet, newMask);
596     }
597
598     // temporary for 2.10
599     private DeserializationConfig _withJsonReadFeatures(FormatFeature... features) {
600         int parserSet = _parserFeatures;
601         int parserMask = _parserFeaturesToChange;
602         int newSet = _formatReadFeatures;
603         int newMask = _formatReadFeaturesToChange;
604         for (FormatFeature f : features) {
605             final int mask = f.getMask();
606             newSet |= mask;
607             newMask |= mask;
608
609             if (f instanceof JsonReadFeature) {
610                 JsonParser.Feature oldF = ((JsonReadFeature) f).mappedFeature();
611                 if (oldF != null) {
612                     final int pmask = oldF.getMask();
613                     parserSet |= pmask;
614                     parserMask |= pmask;
615                 }
616             }
617         }
618         return ((_formatReadFeatures == newSet) && (_formatReadFeaturesToChange == newMask)
619                 && (_parserFeatures == parserSet) && (_parserFeaturesToChange == parserMask)
620                 ) ? this :
621             new DeserializationConfig(this,  _mapperFeatures, _deserFeatures,
622                     parserSet, parserMask, newSet, newMask);
623     }
624
625     // temporary for 2.10
626     private DeserializationConfig _withoutJsonReadFeatures(FormatFeature... features) {
627         int parserSet = _parserFeatures;
628         int parserMask = _parserFeaturesToChange;
629         int newSet = _formatReadFeatures;
630         int newMask = _formatReadFeaturesToChange;
631         for (FormatFeature f : features) {
632             final int mask = f.getMask();
633             newSet &= ~mask;
634             newMask |= mask;
635
636             if (f instanceof JsonReadFeature) {
637                 JsonParser.Feature oldF = ((JsonReadFeature) f).mappedFeature();
638                 if (oldF != null) {
639                     final int pmask = oldF.getMask();
640                     parserSet &= ~pmask;
641                     parserMask |= pmask;
642                 }
643             }
644         }
645         return ((_formatReadFeatures == newSet) && (_formatReadFeaturesToChange == newMask)
646                 && (_parserFeatures == parserSet) && (_parserFeaturesToChange == parserMask)
647                 ) ? this :
648             new DeserializationConfig(this,  _mapperFeatures, _deserFeatures,
649                     parserSet, parserMask, newSet, newMask);
650     }
651
652     /*
653     /**********************************************************
654     /* Life-cycle, deserialization-specific factory methods
655     /**********************************************************
656      */

657
658     /**
659      * Fluent factory method that will construct a new instance with
660      * specified {@link JsonNodeFactory}
661      */

662     public DeserializationConfig with(JsonNodeFactory f) {
663         if (_nodeFactory == f) {
664             return this;
665         }
666         return new DeserializationConfig(this, f);
667     }
668
669     /**
670      * Method that can be used to add a handler that can (try to)
671      * resolve non-fatal deserialization problems.
672      */

673     public DeserializationConfig withHandler(DeserializationProblemHandler h)
674     {
675         // Sanity check: let's prevent adding same handler multiple times
676         if (LinkedNode.contains(_problemHandlers, h)) {
677             return this;
678         }
679         return new DeserializationConfig(this,
680                 new LinkedNode<DeserializationProblemHandler>(h, _problemHandlers));
681     }
682
683     /**
684      * Method for removing all configured problem handlers; usually done to replace
685      * existing handler(s) with different one(s)
686      */

687     public DeserializationConfig withNoProblemHandlers() {
688         if (_problemHandlers == null) {
689             return this;
690         }
691         return new DeserializationConfig(this,
692                 (LinkedNode<DeserializationProblemHandler>) null);
693     }
694
695     /*
696     /**********************************************************
697     /* JsonParser initialization
698     /**********************************************************
699      */

700
701     /**
702      * Method called by {@link ObjectMapper} and {@link ObjectReader}
703      * to modify those {@link com.fasterxml.jackson.core.JsonParser.Feature} settings
704      * that have been configured via this config instance.
705      * 
706      * @since 2.5
707      */

708     public void initialize(JsonParser p) {
709         if (_parserFeaturesToChange != 0) {
710             p.overrideStdFeatures(_parserFeatures, _parserFeaturesToChange);
711         }
712         if (_formatReadFeaturesToChange != 0) {
713             p.overrideFormatFeatures(_formatReadFeatures, _formatReadFeaturesToChange);
714         }
715     }
716
717     /*
718     /**********************************************************
719     /* MapperConfig implementation/overrides: other
720     /**********************************************************
721      */

722
723     @Override
724     public boolean useRootWrapping()
725     {
726         if (_rootName != null) { // empty String disables wrapping; non-empty enables
727             return !_rootName.isEmpty();
728         }
729         return isEnabled(DeserializationFeature.UNWRAP_ROOT_VALUE);
730     }
731
732     public final boolean isEnabled(DeserializationFeature f) {
733         return (_deserFeatures & f.getMask()) != 0;
734     }
735
736     public final boolean isEnabled(JsonParser.Feature f, JsonFactory factory) {
737         int mask = f.getMask();
738         if ((_parserFeaturesToChange & mask) != 0) {
739             return (_parserFeatures & f.getMask()) != 0;
740         }
741         return factory.isEnabled(f);
742     }
743
744     /**
745      * Bulk access method for checking that all features specified by
746      * mask are enabled.
747      * 
748      * @since 2.3
749      */

750     public final boolean hasDeserializationFeatures(int featureMask) {
751         return (_deserFeatures & featureMask) == featureMask;
752     }
753
754     /**
755      * Bulk access method for checking that at least one of features specified by
756      * mask is enabled.
757      * 
758      * @since 2.6
759      */

760     public final boolean hasSomeOfFeatures(int featureMask) {
761         return (_deserFeatures & featureMask) != 0;
762     }
763
764     /**
765      * Bulk access method for getting the bit mask of all {@link DeserializationFeature}s
766      * that are enabled.
767      */

768     public final int getDeserializationFeatures() {
769         return _deserFeatures;
770     }
771
772     /**
773      * Convenience method equivalant to:
774      *<code>
775      *   isEnabled(DeserializationFeature.FAIL_ON_TRAILING_TOKENS)
776      *</code>
777      *
778      * @since 2.9
779      */

780     public final boolean requiresFullValue() {
781         return DeserializationFeature.FAIL_ON_TRAILING_TOKENS.enabledIn(_deserFeatures);
782     }
783
784     /*
785     /**********************************************************
786     /* Other configuration
787     /**********************************************************
788      */

789
790     /**
791      * Method for getting head of the problem handler chain. May be null,
792      * if no handlers have been added.
793      */

794     public LinkedNode<DeserializationProblemHandler> getProblemHandlers() {
795         return _problemHandlers;
796     }
797
798     public final JsonNodeFactory getNodeFactory() {
799         return _nodeFactory;
800     }
801
802     /*
803     /**********************************************************
804     /* Introspection methods
805     /**********************************************************
806      */

807
808     /**
809      * Method that will introspect full bean properties for the purpose
810      * of building a bean deserializer
811      *
812      * @param type Type of class to be introspected
813      */

814     @SuppressWarnings("unchecked")
815     public <T extends BeanDescription> T introspect(JavaType type) {
816         return (T) getClassIntrospector().forDeserialization(this, type, this);
817     }
818
819     /**
820      * Method that will introspect subset of bean properties needed to
821      * construct bean instance.
822      */

823     @SuppressWarnings("unchecked")
824     public <T extends BeanDescription> T introspectForCreation(JavaType type) {
825         return (T) getClassIntrospector().forCreation(this, type, this);
826     }
827
828     /**
829      * @since 2.0
830      */

831     @SuppressWarnings("unchecked")
832     public <T extends BeanDescription> T introspectForBuilder(JavaType type) {
833         return (T) getClassIntrospector().forDeserializationWithBuilder(this, type, this);
834     }
835
836     /*
837     /**********************************************************
838     /* Support for polymorphic type handling
839     /**********************************************************
840      */

841     
842     /**
843      * Helper method that is needed to properly handle polymorphic referenced
844      * types, such as types referenced by {@link java.util.concurrent.atomic.AtomicReference},
845      * or various "optional" types.
846      * 
847      * @since 2.4
848      */

849     public TypeDeserializer findTypeDeserializer(JavaType baseType)
850         throws JsonMappingException
851     {
852         BeanDescription bean = introspectClassAnnotations(baseType.getRawClass());
853         AnnotatedClass ac = bean.getClassInfo();
854         TypeResolverBuilder<?> b = getAnnotationIntrospector().findTypeResolver(this, ac, baseType);
855
856         /* Ok: if there is no explicit type info handler, we may want to
857          * use a default. If so, config object knows what to use.
858          */

859         Collection<NamedType> subtypes = null;
860         if (b == null) {
861             b = getDefaultTyper(baseType);
862             if (b == null) {
863                 return null;
864             }
865         } else {
866             subtypes = getSubtypeResolver().collectAndResolveSubtypesByTypeId(this, ac);
867         }
868         return b.buildTypeDeserializer(this, baseType, subtypes);
869     }
870 }
871