-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
/
Copy pathObjectReader.java
1889 lines (1708 loc) · 66.9 KB
/
ObjectReader.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
package com.fasterxml.jackson.databind;
import java.io.*;
import java.net.URL;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import com.fasterxml.jackson.core.*;
import com.fasterxml.jackson.core.filter.FilteringParserDelegate;
import com.fasterxml.jackson.core.filter.JsonPointerBasedFilter;
import com.fasterxml.jackson.core.filter.TokenFilter;
import com.fasterxml.jackson.core.type.ResolvedType;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.cfg.ContextAttributes;
import com.fasterxml.jackson.databind.deser.DataFormatReaders;
import com.fasterxml.jackson.databind.deser.DefaultDeserializationContext;
import com.fasterxml.jackson.databind.deser.DeserializationProblemHandler;
import com.fasterxml.jackson.databind.node.JsonNodeFactory;
import com.fasterxml.jackson.databind.node.NullNode;
import com.fasterxml.jackson.databind.node.TreeTraversingParser;
import com.fasterxml.jackson.databind.type.SimpleType;
import com.fasterxml.jackson.databind.type.TypeFactory;
/**
* Builder object that can be used for per-serialization configuration of
* deserialization parameters, such as root type to use or object
* to update (instead of constructing new instance).
*<p>
* Uses "mutant factory" pattern so that instances are immutable
* (and thus fully thread-safe with no external synchronization);
* new instances are constructed for different configurations.
* Instances are initially constructed by {@link ObjectMapper} and can be
* reused, shared, cached; both because of thread-safety and because
* instances are relatively light-weight.
*/
public class ObjectReader
extends ObjectCodec
implements Versioned, java.io.Serializable // since 2.1
{
private static final long serialVersionUID = 1L; // since 2.5
private final static JavaType JSON_NODE_TYPE = SimpleType.constructUnsafe(JsonNode.class);
/*
/**********************************************************
/* Immutable configuration from ObjectMapper
/**********************************************************
*/
/**
* General serialization configuration settings; while immutable,
* can use copy-constructor to create modified instances as necessary.
*/
protected final DeserializationConfig _config;
/**
* Blueprint instance of deserialization context; used for creating
* actual instance when needed.
*/
protected final DefaultDeserializationContext _context;
/**
* Factory used for constructing {@link JsonGenerator}s
*/
protected final JsonFactory _parserFactory;
/**
* Flag that indicates whether root values are expected to be unwrapped or not
*/
protected final boolean _unwrapRoot;
/**
* Filter to be consider for JsonParser.
* Default value to be null as filter not considered.
*/
private final TokenFilter _filter;
/*
/**********************************************************
/* Configuration that can be changed during building
/**********************************************************
*/
/**
* Declared type of value to instantiate during deserialization.
* Defines which deserializer to use; as well as base type of instance
* to construct if an updatable value is not configured to be used
* (subject to changes by embedded type information, for polymorphic
* types). If {@link #_valueToUpdate} is non-null, only used for
* locating deserializer.
*/
protected final JavaType _valueType;
/**
* We may pre-fetch deserializer as soon as {@link #_valueType}
* is known, and if so, reuse it afterwards.
* This allows avoiding further deserializer lookups and increases
* performance a bit on cases where readers are reused.
*
* @since 2.1
*/
protected final JsonDeserializer<Object> _rootDeserializer;
/**
* Instance to update with data binding; if any. If null,
* a new instance is created, if non-null, properties of
* this value object will be updated instead.
* Note that value can be of almost any type, except not
* {@link com.fasterxml.jackson.databind.type.ArrayType}; array
* types can not be modified because array size is immutable.
*/
protected final Object _valueToUpdate;
/**
* When using data format that uses a schema, schema is passed
* to parser.
*/
protected final FormatSchema _schema;
/**
* Values that can be injected during deserialization, if any.
*/
protected final InjectableValues _injectableValues;
/**
* Optional detector used for auto-detecting data format that byte-based
* input uses.
*<p>
* NOTE: If defined non-null, <code>readValue()</code> methods that take
* {@link Reader} or {@link String} input <b>will fail with exception</b>,
* because format-detection only works on byte-sources. Also, if format
* can not be detect reliably (as per detector settings),
* a {@link JsonParseException} will be thrown).
*
* @since 2.1
*/
protected final DataFormatReaders _dataFormatReaders;
/*
/**********************************************************
/* Caching
/**********************************************************
*/
/**
* Root-level cached deserializers.
* Passed by {@link ObjectMapper}, shared with it.
*/
final protected ConcurrentHashMap<JavaType, JsonDeserializer<Object>> _rootDeserializers;
/*
/**********************************************************
/* Life-cycle, construction
/**********************************************************
*/
/**
* Constructor used by {@link ObjectMapper} for initial instantiation
*/
protected ObjectReader(ObjectMapper mapper, DeserializationConfig config) {
this(mapper, config, null, null, null, null);
}
/**
* Constructor called when a root deserializer should be fetched based
* on other configuration.
*/
protected ObjectReader(ObjectMapper mapper, DeserializationConfig config,
JavaType valueType, Object valueToUpdate,
FormatSchema schema, InjectableValues injectableValues)
{
_config = config;
_context = mapper._deserializationContext;
_rootDeserializers = mapper._rootDeserializers;
_parserFactory = mapper._jsonFactory;
_valueType = valueType;
_valueToUpdate = valueToUpdate;
if (valueToUpdate != null && valueType.isArrayType()) {
throw new IllegalArgumentException("Can not update an array value");
}
_schema = schema;
_injectableValues = injectableValues;
_unwrapRoot = config.useRootWrapping();
_rootDeserializer = _prefetchRootDeserializer(valueType);
_dataFormatReaders = null;
_filter = null;
}
/**
* Copy constructor used for building variations.
*/
protected ObjectReader(ObjectReader base, DeserializationConfig config,
JavaType valueType, JsonDeserializer<Object> rootDeser, Object valueToUpdate,
FormatSchema schema, InjectableValues injectableValues,
DataFormatReaders dataFormatReaders)
{
_config = config;
_context = base._context;
_rootDeserializers = base._rootDeserializers;
_parserFactory = base._parserFactory;
_valueType = valueType;
_rootDeserializer = rootDeser;
_valueToUpdate = valueToUpdate;
if (valueToUpdate != null && valueType.isArrayType()) {
throw new IllegalArgumentException("Can not update an array value");
}
_schema = schema;
_injectableValues = injectableValues;
_unwrapRoot = config.useRootWrapping();
_dataFormatReaders = dataFormatReaders;
_filter = base._filter;
}
/**
* Copy constructor used when modifying simple feature flags
*/
protected ObjectReader(ObjectReader base, DeserializationConfig config)
{
_config = config;
_context = base._context;
_rootDeserializers = base._rootDeserializers;
_parserFactory = base._parserFactory;
_valueType = base._valueType;
_rootDeserializer = base._rootDeserializer;
_valueToUpdate = base._valueToUpdate;
_schema = base._schema;
_injectableValues = base._injectableValues;
_unwrapRoot = config.useRootWrapping();
_dataFormatReaders = base._dataFormatReaders;
_filter = base._filter;
}
protected ObjectReader(ObjectReader base, JsonFactory f)
{
// may need to override ordering, based on data format capabilities
_config = base._config
.with(MapperFeature.SORT_PROPERTIES_ALPHABETICALLY, f.requiresPropertyOrdering());
_context = base._context;
_rootDeserializers = base._rootDeserializers;
_parserFactory = f;
_valueType = base._valueType;
_rootDeserializer = base._rootDeserializer;
_valueToUpdate = base._valueToUpdate;
_schema = base._schema;
_injectableValues = base._injectableValues;
_unwrapRoot = base._unwrapRoot;
_dataFormatReaders = base._dataFormatReaders;
_filter = base._filter;
}
protected ObjectReader(ObjectReader base, TokenFilter filter) {
_config = base._config;
_context = base._context;
_rootDeserializers = base._rootDeserializers;
_parserFactory = base._parserFactory;
_valueType = base._valueType;
_rootDeserializer = base._rootDeserializer;
_valueToUpdate = base._valueToUpdate;
_schema = base._schema;
_injectableValues = base._injectableValues;
_unwrapRoot = base._unwrapRoot;
_dataFormatReaders = base._dataFormatReaders;
_filter = filter;
}
/**
* Method that will return version information stored in and read from jar
* that contains this class.
*/
@Override
public Version version() {
return com.fasterxml.jackson.databind.cfg.PackageVersion.VERSION;
}
/*
/**********************************************************
/* Methods sub-classes MUST override, used for constructing
/* reader instances, (re)configuring parser instances
/* Added in 2.5
/**********************************************************
*/
/**
* Overridable factory method called by various "withXxx()" methods
*
* @since 2.5
*/
protected ObjectReader _new(ObjectReader base, JsonFactory f) {
return new ObjectReader(base, f);
}
/**
* Overridable factory method called by various "withXxx()" methods
*
* @since 2.5
*/
protected ObjectReader _new(ObjectReader base, DeserializationConfig config) {
return new ObjectReader(base, config);
}
/**
* Overridable factory method called by various "withXxx()" methods
*
* @since 2.5
*/
protected ObjectReader _new(ObjectReader base, DeserializationConfig config,
JavaType valueType, JsonDeserializer<Object> rootDeser, Object valueToUpdate,
FormatSchema schema, InjectableValues injectableValues,
DataFormatReaders dataFormatReaders) {
return new ObjectReader(base, config, valueType, rootDeser, valueToUpdate,
schema, injectableValues, dataFormatReaders);
}
/**
* Factory method used to create {@link MappingIterator} instances;
* either default, or custom subtype.
*
* @since 2.5
*/
protected <T> MappingIterator<T> _newIterator(JsonParser p, DeserializationContext ctxt,
JsonDeserializer<?> deser, boolean parserManaged)
{
return new MappingIterator<T>(_valueType, p, ctxt,
deser, parserManaged, _valueToUpdate);
}
/*
/**********************************************************
/* Methods sub-classes may choose to override, if customized
/* initialization is needed.
/**********************************************************
*/
/**
* NOTE: changed from static to non-static in 2.5; unfortunate but
* necessary change to support overridability
*/
protected JsonToken _initForReading(JsonParser p) throws IOException
{
if (_schema != null) {
p.setSchema(_schema);
}
_config.initialize(p); // since 2.5
/* First: must point to a token; if not pointing to one, advance.
* This occurs before first read from JsonParser, as well as
* after clearing of current token.
*/
JsonToken t = p.getCurrentToken();
if (t == null) { // and then we must get something...
t = p.nextToken();
if (t == null) {
// Throw mapping exception, since it's failure to map, not an actual parsing problem
throw JsonMappingException.from(p, "No content to map due to end-of-input");
}
}
return t;
}
/**
* Alternative to {@link #_initForReading(JsonParser)} used in cases where reading
* of multiple values means that we may or may not want to advance the stream,
* but need to do other initialization.
*<p>
* Base implementation only sets configured {@link FormatSchema}, if any, on parser.
*
* @since 2.5
*/
protected void _initForMultiRead(JsonParser p) throws IOException {
if (_schema != null) {
p.setSchema(_schema);
}
_config.initialize(p); // since 2.5
}
/*
/**********************************************************
/* Life-cycle, fluent factory methods for DeserializationFeatures
/**********************************************************
*/
/**
* Method for constructing a new reader instance that is configured
* with specified feature enabled.
*/
public ObjectReader with(DeserializationFeature feature) {
return _with(_config.with(feature));
}
/**
* Method for constructing a new reader instance that is configured
* with specified features enabled.
*/
public ObjectReader with(DeserializationFeature first,
DeserializationFeature... other)
{
return _with(_config.with(first, other));
}
/**
* Method for constructing a new reader instance that is configured
* with specified features enabled.
*/
public ObjectReader withFeatures(DeserializationFeature... features) {
return _with(_config.withFeatures(features));
}
/**
* Method for constructing a new reader instance that is configured
* with specified feature disabled.
*/
public ObjectReader without(DeserializationFeature feature) {
return _with(_config.without(feature));
}
/**
* Method for constructing a new reader instance that is configured
* with specified features disabled.
*/
public ObjectReader without(DeserializationFeature first,
DeserializationFeature... other) {
return _with(_config.without(first, other));
}
/**
* Method for constructing a new reader instance that is configured
* with specified features disabled.
*/
public ObjectReader withoutFeatures(DeserializationFeature... features) {
return _with(_config.withoutFeatures(features));
}
/*
/**********************************************************
/* Life-cycle, fluent factory methods for JsonParser.Features
/**********************************************************
*/
/**
* Method for constructing a new reader instance that is configured
* with specified feature enabled.
*/
public ObjectReader with(JsonParser.Feature feature) {
return _with(_config.with(feature));
}
/**
* Method for constructing a new reader instance that is configured
* with specified features enabled.
*/
public ObjectReader withFeatures(JsonParser.Feature... features) {
return _with(_config.withFeatures(features));
}
/**
* Method for constructing a new reader instance that is configured
* with specified feature disabled.
*/
public ObjectReader without(JsonParser.Feature feature) {
return _with(_config.without(feature));
}
/**
* Method for constructing a new reader instance that is configured
* with specified features disabled.
*/
public ObjectReader withoutFeatures(JsonParser.Feature... features) {
return _with(_config.withoutFeatures(features));
}
/*
/**********************************************************
/* Life-cycle, fluent factory methods for FormatFeature (2.7)
/**********************************************************
*/
/**
* Method for constructing a new reader instance that is configured
* with specified feature enabled.
*
* @since 2.7
*/
public ObjectReader with(FormatFeature feature) {
return _with(_config.with(feature));
}
/**
* Method for constructing a new reader instance that is configured
* with specified features enabled.
*
* @since 2.7
*/
public ObjectReader withFeatures(FormatFeature... features) {
return _with(_config.withFeatures(features));
}
/**
* Method for constructing a new reader instance that is configured
* with specified feature disabled.
*
* @since 2.7
*/
public ObjectReader without(FormatFeature feature) {
return _with(_config.without(feature));
}
/**
* Method for constructing a new reader instance that is configured
* with specified features disabled.
*
* @since 2.7
*/
public ObjectReader withoutFeatures(FormatFeature... features) {
return _with(_config.withoutFeatures(features));
}
/*
/**********************************************************
/* Life-cycle, fluent factory methods, other
/**********************************************************
*/
/**
* Mutant factory method that will construct a new instance that has
* specified underlying {@link DeserializationConfig}.
*<p>
* NOTE: use of this method is not recommended, as there are many other
* re-configuration methods available.
*/
public ObjectReader with(DeserializationConfig config) {
return _with(config);
}
/**
* Method for constructing a new instance with configuration that uses
* passed {@link InjectableValues} to provide injectable values.
*<p>
* Note that the method does NOT change state of this reader, but
* rather construct and returns a newly configured instance.
*/
public ObjectReader with(InjectableValues injectableValues)
{
if (_injectableValues == injectableValues) {
return this;
}
return _new(this, _config,
_valueType, _rootDeserializer, _valueToUpdate,
_schema, injectableValues, _dataFormatReaders);
}
/**
* Method for constructing a new reader instance with configuration that uses
* passed {@link JsonNodeFactory} for constructing {@link JsonNode}
* instances.
*<p>
* Note that the method does NOT change state of this reader, but
* rather construct and returns a newly configured instance.
*/
public ObjectReader with(JsonNodeFactory f) {
return _with(_config.with(f));
}
/**
* Method for constructing a new reader instance with configuration that uses
* passed {@link JsonFactory} for constructing underlying Readers.
*<p>
* NOTE: only factories that <b>DO NOT REQUIRE SPECIAL MAPPERS</b>
* (that is, ones that return <code>false</code> for
* {@link JsonFactory#requiresCustomCodec()}) can be used: trying
* to use one that requires custom codec will throw exception
*
* @since 2.1
*/
public ObjectReader with(JsonFactory f) {
if (f == _parserFactory) {
return this;
}
ObjectReader r = _new(this, f);
// Also, try re-linking, if possible...
if (f.getCodec() == null) {
f.setCodec(r);
}
return r;
}
/**
* Method for constructing a new instance with configuration that
* specifies what root name to expect for "root name unwrapping".
* See {@link DeserializationConfig#withRootName(String)} for
* details.
*<p>
* Note that the method does NOT change state of this reader, but
* rather construct and returns a newly configured instance.
*/
public ObjectReader withRootName(String rootName) {
return _with(_config.withRootName(rootName));
}
/**
* @since 2.6
*/
public ObjectReader withRootName(PropertyName rootName) {
return _with(_config.withRootName(rootName));
}
/**
* Convenience method that is same as calling:
*<code>
* withRootName("")
*</code>
* which will forcibly prevent use of root name wrapping when writing
* values with this {@link ObjectReader}.
*
* @since 2.6
*/
public ObjectReader withoutRootName() {
return _with(_config.withRootName(PropertyName.NO_NAME));
}
/**
* Method for constructing a new instance with configuration that
* passes specified {@link FormatSchema} to {@link JsonParser} that
* is constructed for parsing content.
*<p>
* Note that the method does NOT change state of this reader, but
* rather construct and returns a newly configured instance.
*/
public ObjectReader with(FormatSchema schema)
{
if (_schema == schema) {
return this;
}
_verifySchemaType(schema);
return _new(this, _config, _valueType, _rootDeserializer, _valueToUpdate,
schema, _injectableValues, _dataFormatReaders);
}
/**
* Method for constructing a new reader instance that is configured
* to data bind into specified type.
*<p>
* Note that the method does NOT change state of this reader, but
* rather construct and returns a newly configured instance.
*
* @since 2.5
*/
public ObjectReader forType(JavaType valueType)
{
if (valueType != null && valueType.equals(_valueType)) {
return this;
}
JsonDeserializer<Object> rootDeser = _prefetchRootDeserializer(valueType);
// type is stored here, no need to make a copy of config
DataFormatReaders det = _dataFormatReaders;
if (det != null) {
det = det.withType(valueType);
}
return _new(this, _config, valueType, rootDeser,
_valueToUpdate, _schema, _injectableValues, det);
}
/**
* Method for constructing a new reader instance that is configured
* to data bind into specified type.
*<p>
* Note that the method does NOT change state of this reader, but
* rather construct and returns a newly configured instance.
*
* @since 2.5
*/
public ObjectReader forType(Class<?> valueType) {
return forType(_config.constructType(valueType));
}
/**
* Method for constructing a new reader instance that is configured
* to data bind into specified type.
*<p>
* Note that the method does NOT change state of this reader, but
* rather construct and returns a newly configured instance.
*
* @since 2.5
*/
public ObjectReader forType(TypeReference<?> valueTypeRef) {
return forType(_config.getTypeFactory().constructType(valueTypeRef.getType()));
}
/**
* @deprecated since 2.5 Use {@link #forType(JavaType)} instead
*/
@Deprecated
public ObjectReader withType(JavaType valueType) {
return forType(valueType);
}
/**
* @deprecated since 2.5 Use {@link #forType(Class)} instead
*/
@Deprecated
public ObjectReader withType(Class<?> valueType) {
return forType(_config.constructType(valueType));
}
/**
* @deprecated since 2.5 Use {@link #forType(Class)} instead
*/
@Deprecated
public ObjectReader withType(java.lang.reflect.Type valueType) {
return forType(_config.getTypeFactory().constructType(valueType));
}
/**
* @deprecated since 2.5 Use {@link #forType(TypeReference)} instead
*/
@Deprecated
public ObjectReader withType(TypeReference<?> valueTypeRef) {
return forType(_config.getTypeFactory().constructType(valueTypeRef.getType()));
}
/**
* Method for constructing a new instance with configuration that
* updates passed Object (as root value), instead of constructing
* a new value.
*<p>
* Note that the method does NOT change state of this reader, but
* rather construct and returns a newly configured instance.
*/
public ObjectReader withValueToUpdate(Object value)
{
if (value == _valueToUpdate) return this;
if (value == null) {
throw new IllegalArgumentException("cat not update null value");
}
JavaType t;
/* no real benefit from pre-fetching, as updating readers are much
* less likely to be reused, and value type may also be forced
* with a later chained call...
*/
if (_valueType == null) {
t = _config.constructType(value.getClass());
} else {
t = _valueType;
}
return _new(this, _config, t, _rootDeserializer, value,
_schema, _injectableValues, _dataFormatReaders);
}
/**
* Method for constructing a new instance with configuration that
* uses specified View for filtering.
*<p>
* Note that the method does NOT change state of this reader, but
* rather construct and returns a newly configured instance.
*/
public ObjectReader withView(Class<?> activeView) {
return _with(_config.withView(activeView));
}
public ObjectReader with(Locale l) {
return _with(_config.with(l));
}
public ObjectReader with(TimeZone tz) {
return _with(_config.with(tz));
}
public ObjectReader withHandler(DeserializationProblemHandler h) {
return _with(_config.withHandler(h));
}
public ObjectReader with(Base64Variant defaultBase64) {
return _with(_config.with(defaultBase64));
}
/**
* Fluent factory method for constructing a reader that will try to
* auto-detect underlying data format, using specified list of
* {@link JsonFactory} instances, and default {@link DataFormatReaders} settings
* (for customized {@link DataFormatReaders}, you can construct instance yourself).
* to construct appropriate {@link JsonParser} for actual parsing.
*<p>
* Note: since format detection only works with byte sources, it is possible to
* get a failure from some 'readValue()' methods. Also, if input can not be reliably
* (enough) detected as one of specified types, an exception will be thrown.
*<p>
* Note: not all {@link JsonFactory} types can be passed: specifically, ones that
* require "custom codec" (like XML factory) will not work. Instead, use
* method that takes {@link ObjectReader} instances instead of factories.
*
* @param readers Data formats accepted, in decreasing order of priority (that is,
* matches checked in listed order, first match wins)
*
* @return Newly configured writer instance
*
* @since 2.1
*/
public ObjectReader withFormatDetection(ObjectReader... readers) {
return withFormatDetection(new DataFormatReaders(readers));
}
/**
* Fluent factory method for constructing a reader that will try to
* auto-detect underlying data format, using specified
* {@link DataFormatReaders}.
*<p>
* NOTE: since format detection only works with byte sources, it is possible to
* get a failure from some 'readValue()' methods. Also, if input can not be reliably
* (enough) detected as one of specified types, an exception will be thrown.
*
* @param readers DataFormatReaders to use for detecting underlying format.
*
* @return Newly configured writer instance
*
* @since 2.1
*/
public ObjectReader withFormatDetection(DataFormatReaders readers) {
return _new(this, _config, _valueType, _rootDeserializer, _valueToUpdate,
_schema, _injectableValues, readers);
}
/**
* @since 2.3
*/
public ObjectReader with(ContextAttributes attrs) {
return _with(_config.with(attrs));
}
/**
* @since 2.3
*/
public ObjectReader withAttributes(Map<?,?> attrs) {
return _with(_config.withAttributes(attrs));
}
/**
* @since 2.3
*/
public ObjectReader withAttribute(Object key, Object value) {
return _with( _config.withAttribute(key, value));
}
/**
* @since 2.3
*/
public ObjectReader withoutAttribute(Object key) {
return _with(_config.withoutAttribute(key));
}
/*
/**********************************************************
/* Overridable factory methods may override
/**********************************************************
*/
protected ObjectReader _with(DeserializationConfig newConfig) {
if (newConfig == _config) {
return this;
}
ObjectReader r = _new(this, newConfig);
if (_dataFormatReaders != null) {
r = r.withFormatDetection(_dataFormatReaders.with(newConfig));
}
return r;
}
/*
/**********************************************************
/* Simple accessors
/**********************************************************
*/
public boolean isEnabled(DeserializationFeature f) {
return _config.isEnabled(f);
}
public boolean isEnabled(MapperFeature f) {
return _config.isEnabled(f);
}
public boolean isEnabled(JsonParser.Feature f) {
return _parserFactory.isEnabled(f);
}
/**
* @since 2.2
*/
public DeserializationConfig getConfig() {
return _config;
}
/**
* @since 2.1
*/
@Override
public JsonFactory getFactory() {
return _parserFactory;
}
public TypeFactory getTypeFactory() {
return _config.getTypeFactory();
}
/**
* @since 2.3
*/
public ContextAttributes getAttributes() {
return _config.getAttributes();
}
/**
* @since 2.6
*/
public InjectableValues getInjectableValues() {
return _injectableValues;
}
/*
/**********************************************************
/* Deserialization methods; basic ones to support ObjectCodec first
/* (ones that take JsonParser)
/**********************************************************
*/
/**
* Method that binds content read using given parser, using
* configuration of this reader, including expected result type.
* Value return is either newly constructed, or root value that
* was specified with {@link #withValueToUpdate(Object)}.
*<p>
* NOTE: this method never tries to auto-detect format, since actual
* (data-format specific) parser is given.
*/
@SuppressWarnings("unchecked")
public <T> T readValue(JsonParser p) throws IOException
{
return (T) _bind(p, _valueToUpdate);
}
/**
* Convenience method that binds content read using given parser, using
* configuration of this reader, except that expected value type
* is specified with the call (instead of currently configured root type).
* Value return is either newly constructed, or root value that
* was specified with {@link #withValueToUpdate(Object)}.
*<p>
* NOTE: this method never tries to auto-detect format, since actual
* (data-format specific) parser is given.
*/
@SuppressWarnings("unchecked")
@Override
public <T> T readValue(JsonParser p, Class<T> valueType) throws IOException
{
return (T) forType(valueType).readValue(p);
}
/**
* Convenience method that binds content read using given parser, using
* configuration of this reader, except that expected value type
* is specified with the call (instead of currently configured root type).
* Value return is either newly constructed, or root value that
* was specified with {@link #withValueToUpdate(Object)}.
*<p>
* NOTE: this method never tries to auto-detect format, since actual
* (data-format specific) parser is given.
*/
@SuppressWarnings("unchecked")
@Override
public <T> T readValue(JsonParser p, TypeReference<?> valueTypeRef) throws IOException
{
return (T) forType(valueTypeRef).readValue(p);
}
/**
* Convenience method that binds content read using given parser, using
* configuration of this reader, except that expected value type
* is specified with the call (instead of currently configured root type).
* Value return is either newly constructed, or root value that
* was specified with {@link #withValueToUpdate(Object)}.
*<p>
* NOTE: this method never tries to auto-detect format, since actual
* (data-format specific) parser is given.
*/
@Override
@SuppressWarnings("unchecked")
public <T> T readValue(JsonParser p, ResolvedType valueType) throws IOException, JsonProcessingException {
return (T) forType((JavaType)valueType).readValue(p);
}
/**
* Type-safe overloaded method, basically alias for {@link #readValue(JsonParser, ResolvedType)}.
*<p>
* NOTE: this method never tries to auto-detect format, since actual