Skip to content

Commit a8a233f

Browse files
authored
Implement core of #3405 (#3420)
1 parent 594f580 commit a8a233f

14 files changed

+814
-78
lines changed

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

+11-3
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import java.util.TimeZone;
66

77
import com.fasterxml.jackson.annotation.*;
8-
8+
import com.fasterxml.jackson.databind.cfg.DatatypeFeature;
99
import com.fasterxml.jackson.databind.cfg.HandlerInstantiator;
1010
import com.fasterxml.jackson.databind.cfg.MapperConfig;
1111
import com.fasterxml.jackson.databind.introspect.Annotated;
@@ -61,9 +61,9 @@ public abstract class DatabindContext
6161
/* Access to specific config settings
6262
/**********************************************************
6363
*/
64-
64+
6565
/**
66-
* Convenience method for checking whether specified serialization
66+
* Convenience method for checking whether specified Mapper
6767
* feature is enabled or not.
6868
* Shortcut for:
6969
*<pre>
@@ -72,6 +72,14 @@ public abstract class DatabindContext
7272
*/
7373
public abstract boolean isEnabled(MapperFeature feature);
7474

75+
/**
76+
* Method for checking whether specified datatype
77+
* feature is enabled or not.
78+
*
79+
* @since 2.14
80+
*/
81+
public abstract boolean isEnabled(DatatypeFeature feature);
82+
7583
/**
7684
* Convenience method for accessing serialization view in use (if any); equivalent to:
7785
*<pre>

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

+53-23
Original file line numberDiff line numberDiff line change
@@ -110,13 +110,14 @@ public final class DeserializationConfig
110110
/**
111111
* Constructor used by ObjectMapper to create default configuration object instance.
112112
*
113-
* @since 2.12
113+
* @since 2.14
114114
*/
115115
public DeserializationConfig(BaseSettings base,
116116
SubtypeResolver str, SimpleMixInResolver mixins, RootNameLookup rootNames,
117-
ConfigOverrides configOverrides, CoercionConfigs coercionConfigs)
117+
ConfigOverrides configOverrides, CoercionConfigs coercionConfigs,
118+
DatatypeFeatures datatypeFeatures)
118119
{
119-
super(base, str, mixins, rootNames, configOverrides);
120+
super(base, str, mixins, rootNames, configOverrides, datatypeFeatures);
120121
_deserFeatures = DESER_FEATURE_DEFAULTS;
121122
_problemHandlers = null;
122123
_nodeFactory = JsonNodeFactory.instance;
@@ -131,7 +132,7 @@ public DeserializationConfig(BaseSettings base,
131132
/**
132133
* Copy-constructor used for making a copy used by new {@link ObjectMapper}.
133134
*
134-
* @since 2.12
135+
* @since 2.14
135136
*/
136137
protected DeserializationConfig(DeserializationConfig src,
137138
SubtypeResolver str, SimpleMixInResolver mixins, RootNameLookup rootNames,
@@ -150,22 +151,6 @@ protected DeserializationConfig(DeserializationConfig src,
150151
_formatReadFeaturesToChange = src._formatReadFeaturesToChange;
151152
}
152153

153-
@Deprecated // since 2.12, remove from 2.13 or later
154-
public DeserializationConfig(BaseSettings base,
155-
SubtypeResolver str, SimpleMixInResolver mixins, RootNameLookup rootNames,
156-
ConfigOverrides configOverrides) {
157-
this(base, str, mixins, rootNames, configOverrides,
158-
new CoercionConfigs());
159-
}
160-
161-
@Deprecated // since 2.11.2, remove from 2.13 or later
162-
protected DeserializationConfig(DeserializationConfig src,
163-
SimpleMixInResolver mixins, RootNameLookup rootNames,
164-
ConfigOverrides configOverrides) {
165-
this(src, src._subtypeResolver, mixins, rootNames, configOverrides,
166-
new CoercionConfigs());
167-
}
168-
169154
/*
170155
/**********************************************************
171156
/* Life-cycle, secondary constructors to support
@@ -322,6 +307,24 @@ protected DeserializationConfig(DeserializationConfig src, SimpleMixInResolver m
322307
_formatReadFeaturesToChange = src._formatReadFeaturesToChange;
323308
}
324309

310+
/**
311+
* @since 2.14
312+
*/
313+
protected DeserializationConfig(DeserializationConfig src,
314+
DatatypeFeatures datatypeFeatures)
315+
{
316+
super(src, datatypeFeatures);
317+
_deserFeatures = src._deserFeatures;
318+
_problemHandlers = src._problemHandlers;
319+
_nodeFactory = src._nodeFactory;
320+
_coercionConfigs = src._coercionConfigs;
321+
_ctorDetector = src._ctorDetector;
322+
_parserFeatures = src._parserFeatures;
323+
_parserFeaturesToChange = src._parserFeaturesToChange;
324+
_formatReadFeatures = src._formatReadFeatures;
325+
_formatReadFeaturesToChange = src._formatReadFeaturesToChange;
326+
}
327+
325328
// for unit tests only:
326329
protected BaseSettings getBaseSettings() { return _base; }
327330

@@ -343,6 +346,11 @@ protected final DeserializationConfig _withMapperFeatures(long mapperFeatures) {
343346
_formatReadFeatures, _formatReadFeaturesToChange);
344347
}
345348

349+
@Override
350+
protected final DeserializationConfig _with(DatatypeFeatures dtFeatures) {
351+
return new DeserializationConfig(this, dtFeatures);
352+
}
353+
346354
/*
347355
/**********************************************************
348356
/* Life-cycle, specific factory methods from MapperConfig
@@ -811,8 +819,16 @@ public boolean useRootWrapping()
811819
return isEnabled(DeserializationFeature.UNWRAP_ROOT_VALUE);
812820
}
813821

814-
public final boolean isEnabled(DeserializationFeature f) {
815-
return (_deserFeatures & f.getMask()) != 0;
822+
/**
823+
* Accessor for checking whether give {@link DeserializationFeature}
824+
* is enabled or not.
825+
*
826+
* @param feature Feature to check
827+
*
828+
* @return True if feature is enabled; false otherwise
829+
*/
830+
public final boolean isEnabled(DeserializationFeature feature) {
831+
return (_deserFeatures & feature.getMask()) != 0;
816832
}
817833

818834
public final boolean isEnabled(JsonParser.Feature f, JsonFactory factory) {
@@ -852,7 +868,7 @@ public final int getDeserializationFeatures() {
852868
}
853869

854870
/**
855-
* Convenience method equivalant to:
871+
* Convenience method equivalent to:
856872
*<code>
857873
* isEnabled(DeserializationFeature.FAIL_ON_TRAILING_TOKENS)
858874
*</code>
@@ -863,6 +879,20 @@ public final boolean requiresFullValue() {
863879
return DeserializationFeature.FAIL_ON_TRAILING_TOKENS.enabledIn(_deserFeatures);
864880
}
865881

882+
/**
883+
* Accessor for checking whether give {@link DatatypeFeature}
884+
* is enabled or not.
885+
*
886+
* @param feature Feature to check
887+
*
888+
* @return True if feature is enabled; false otherwise
889+
*
890+
* @since 2.14
891+
*/
892+
public final boolean isEnabled(DatatypeFeature feature) {
893+
return _datatypeFeatures.isEnabled(feature);
894+
}
895+
866896
/*
867897
/**********************************************************
868898
/* Other configuration

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

+6
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import com.fasterxml.jackson.databind.cfg.CoercionAction;
1616
import com.fasterxml.jackson.databind.cfg.CoercionInputShape;
1717
import com.fasterxml.jackson.databind.cfg.ContextAttributes;
18+
import com.fasterxml.jackson.databind.cfg.DatatypeFeature;
1819
import com.fasterxml.jackson.databind.deser.*;
1920
import com.fasterxml.jackson.databind.deser.impl.ObjectIdReader;
2021
import com.fasterxml.jackson.databind.deser.impl.ReadableObjectId;
@@ -276,6 +277,11 @@ public final boolean isEnabled(MapperFeature feature) {
276277
return _config.isEnabled(feature);
277278
}
278279

280+
@Override // @since 2.14
281+
public final boolean isEnabled(DatatypeFeature feature) {
282+
return _config.isEnabled(feature);
283+
}
284+
279285
@Override
280286
public final JsonFormat.Value getDefaultPropertyFormat(Class<?> baseType) {
281287
return _config.getDefaultPropertyFormat(baseType);

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

+29-6
Original file line numberDiff line numberDiff line change
@@ -658,10 +658,12 @@ public ObjectMapper(JsonFactory jf,
658658
_configOverrides = new ConfigOverrides();
659659
_coercionConfigs = new CoercionConfigs();
660660
_serializationConfig = new SerializationConfig(base,
661-
_subtypeResolver, mixins, rootNames, _configOverrides);
661+
_subtypeResolver, mixins, rootNames, _configOverrides,
662+
DatatypeFeatures.defaultFeatures());
662663
_deserializationConfig = new DeserializationConfig(base,
663664
_subtypeResolver, mixins, rootNames, _configOverrides,
664-
_coercionConfigs);
665+
_coercionConfigs,
666+
DatatypeFeatures.defaultFeatures());
665667

666668
// Some overrides we may need
667669
final boolean needOrder = _jsonFactory.requiresPropertyOrdering();
@@ -880,7 +882,7 @@ public boolean isEnabled(MapperFeature f) {
880882
public boolean isEnabled(DeserializationFeature f) {
881883
return ObjectMapper.this.isEnabled(f);
882884
}
883-
885+
884886
@Override
885887
public boolean isEnabled(SerializationFeature f) {
886888
return ObjectMapper.this.isEnabled(f);
@@ -2569,7 +2571,7 @@ public ObjectMapper disable(SerializationFeature first,
25692571
_serializationConfig = _serializationConfig.without(first, f);
25702572
return this;
25712573
}
2572-
2574+
25732575
/*
25742576
/**********************************************************
25752577
/* Configuration, simple features: DeserializationFeature
@@ -2612,7 +2614,7 @@ public ObjectMapper enable(DeserializationFeature first,
26122614
_deserializationConfig = _deserializationConfig.with(first, f);
26132615
return this;
26142616
}
2615-
2617+
26162618
/**
26172619
* Method for enabling specified {@link DeserializationConfig} features.
26182620
* Modifies and returns this instance; no new object is created.
@@ -2631,7 +2633,28 @@ public ObjectMapper disable(DeserializationFeature first,
26312633
_deserializationConfig = _deserializationConfig.without(first, f);
26322634
return this;
26332635
}
2634-
2636+
2637+
/*
2638+
/**********************************************************
2639+
/* Configuration, simple features: DatatypeFeature
2640+
/**********************************************************
2641+
*/
2642+
2643+
/**
2644+
* Method for changing state of an on/off datatype-specific feature for
2645+
* this object mapper.
2646+
*/
2647+
public ObjectMapper configure(DatatypeFeature f, boolean state) {
2648+
if (state) {
2649+
_deserializationConfig = _deserializationConfig.with(f);
2650+
_serializationConfig = _serializationConfig.with(f);
2651+
} else {
2652+
_deserializationConfig = _deserializationConfig.without(f);
2653+
_serializationConfig = _serializationConfig.without(f);
2654+
}
2655+
return this;
2656+
}
2657+
26352658
/*
26362659
/**********************************************************
26372660
/* Configuration, simple features: JsonParser.Feature

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

+54
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import com.fasterxml.jackson.core.type.TypeReference;
1616

1717
import com.fasterxml.jackson.databind.cfg.ContextAttributes;
18+
import com.fasterxml.jackson.databind.cfg.DatatypeFeature;
1819
import com.fasterxml.jackson.databind.deser.DataFormatReaders;
1920
import com.fasterxml.jackson.databind.deser.DefaultDeserializationContext;
2021
import com.fasterxml.jackson.databind.deser.DeserializationProblemHandler;
@@ -435,6 +436,52 @@ public ObjectReader withoutFeatures(DeserializationFeature... features) {
435436
return _with(_config.withoutFeatures(features));
436437
}
437438

439+
/*
440+
/**********************************************************************
441+
/* Life-cycle, fluent factory methods for DatatypeFeatures (2.14+)
442+
/**********************************************************************
443+
*/
444+
445+
/**
446+
* Method for constructing a new reader instance that is configured
447+
* with specified feature enabled.
448+
*
449+
* @since 2.14
450+
*/
451+
public ObjectReader with(DatatypeFeature feature) {
452+
return _with(_config.with(feature));
453+
}
454+
455+
/**
456+
* Method for constructing a new reader instance that is configured
457+
* with specified features enabled.
458+
*
459+
* @since 2.14
460+
*/
461+
public ObjectReader withFeatures(DatatypeFeature... features) {
462+
return _with(_config.withFeatures(features));
463+
}
464+
465+
/**
466+
* Method for constructing a new reader instance that is configured
467+
* with specified feature disabled.
468+
*
469+
* @since 2.14
470+
*/
471+
public ObjectReader without(DatatypeFeature feature) {
472+
return _with(_config.without(feature));
473+
}
474+
475+
/**
476+
* Method for constructing a new reader instance that is configured
477+
* with specified features disabled.
478+
*
479+
* @since 2.14
480+
*/
481+
public ObjectReader withoutFeatures(DatatypeFeature... features) {
482+
return _with(_config.withoutFeatures(features));
483+
}
484+
438485
/*
439486
/**********************************************************
440487
/* Life-cycle, fluent factory methods for JsonParser.Features
@@ -953,6 +1000,13 @@ public boolean isEnabled(MapperFeature f) {
9531000
return _config.isEnabled(f);
9541001
}
9551002

1003+
/**
1004+
* @since 2.14
1005+
*/
1006+
public boolean isEnabled(DatatypeFeature f) {
1007+
return _config.isEnabled(f);
1008+
}
1009+
9561010
public boolean isEnabled(JsonParser.Feature f) {
9571011
return _config.isEnabled(f, _parserFactory);
9581012
}

0 commit comments

Comments
 (0)