Skip to content

Commit

Permalink
Initial implementation of #3405 mostly complete.
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Mar 19, 2022
1 parent e5a206d commit f471dc8
Show file tree
Hide file tree
Showing 11 changed files with 357 additions and 76 deletions.
14 changes: 11 additions & 3 deletions src/main/java/com/fasterxml/jackson/databind/DatabindContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import java.util.TimeZone;

import com.fasterxml.jackson.annotation.*;

import com.fasterxml.jackson.databind.cfg.DatatypeFeature;
import com.fasterxml.jackson.databind.cfg.HandlerInstantiator;
import com.fasterxml.jackson.databind.cfg.MapperConfig;
import com.fasterxml.jackson.databind.introspect.Annotated;
Expand Down Expand Up @@ -61,9 +61,9 @@ public abstract class DatabindContext
/* Access to specific config settings
/**********************************************************
*/

/**
* Convenience method for checking whether specified serialization
* Convenience method for checking whether specified Mapper
* feature is enabled or not.
* Shortcut for:
*<pre>
Expand All @@ -72,6 +72,14 @@ public abstract class DatabindContext
*/
public abstract boolean isEnabled(MapperFeature feature);

/**
* Method for checking whether specified datatype
* feature is enabled or not.
*
* @since 2.14
*/
public abstract boolean isEnabled(DatatypeFeature feature);

/**
* Convenience method for accessing serialization view in use (if any); equivalent to:
*<pre>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,13 +110,14 @@ public final class DeserializationConfig
/**
* Constructor used by ObjectMapper to create default configuration object instance.
*
* @since 2.12
* @since 2.14
*/
public DeserializationConfig(BaseSettings base,
SubtypeResolver str, SimpleMixInResolver mixins, RootNameLookup rootNames,
ConfigOverrides configOverrides, CoercionConfigs coercionConfigs)
ConfigOverrides configOverrides, CoercionConfigs coercionConfigs,
DatatypeFeatures datatypeFeatures)
{
super(base, str, mixins, rootNames, configOverrides);
super(base, str, mixins, rootNames, configOverrides, datatypeFeatures);
_deserFeatures = DESER_FEATURE_DEFAULTS;
_problemHandlers = null;
_nodeFactory = JsonNodeFactory.instance;
Expand All @@ -131,7 +132,7 @@ public DeserializationConfig(BaseSettings base,
/**
* Copy-constructor used for making a copy used by new {@link ObjectMapper}.
*
* @since 2.12
* @since 2.14
*/
protected DeserializationConfig(DeserializationConfig src,
SubtypeResolver str, SimpleMixInResolver mixins, RootNameLookup rootNames,
Expand All @@ -150,22 +151,6 @@ protected DeserializationConfig(DeserializationConfig src,
_formatReadFeaturesToChange = src._formatReadFeaturesToChange;
}

@Deprecated // since 2.12, remove from 2.13 or later
public DeserializationConfig(BaseSettings base,
SubtypeResolver str, SimpleMixInResolver mixins, RootNameLookup rootNames,
ConfigOverrides configOverrides) {
this(base, str, mixins, rootNames, configOverrides,
new CoercionConfigs());
}

@Deprecated // since 2.11.2, remove from 2.13 or later
protected DeserializationConfig(DeserializationConfig src,
SimpleMixInResolver mixins, RootNameLookup rootNames,
ConfigOverrides configOverrides) {
this(src, src._subtypeResolver, mixins, rootNames, configOverrides,
new CoercionConfigs());
}

/*
/**********************************************************
/* Life-cycle, secondary constructors to support
Expand Down Expand Up @@ -322,6 +307,24 @@ protected DeserializationConfig(DeserializationConfig src, SimpleMixInResolver m
_formatReadFeaturesToChange = src._formatReadFeaturesToChange;
}

/**
* @since 2.14
*/
protected DeserializationConfig(DeserializationConfig src,
DatatypeFeatures datatypeFeatures)
{
super(src, datatypeFeatures);
_deserFeatures = src._deserFeatures;
_problemHandlers = src._problemHandlers;
_nodeFactory = src._nodeFactory;
_coercionConfigs = src._coercionConfigs;
_ctorDetector = src._ctorDetector;
_parserFeatures = src._parserFeatures;
_parserFeaturesToChange = src._parserFeaturesToChange;
_formatReadFeatures = src._formatReadFeatures;
_formatReadFeaturesToChange = src._formatReadFeaturesToChange;
}

// for unit tests only:
protected BaseSettings getBaseSettings() { return _base; }

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

@Override
protected final DeserializationConfig _with(DatatypeFeatures dtFeatures) {
return new DeserializationConfig(this, dtFeatures);
}

/*
/**********************************************************
/* Life-cycle, specific factory methods from MapperConfig
Expand Down Expand Up @@ -811,8 +819,16 @@ public boolean useRootWrapping()
return isEnabled(DeserializationFeature.UNWRAP_ROOT_VALUE);
}

public final boolean isEnabled(DeserializationFeature f) {
return (_deserFeatures & f.getMask()) != 0;
/**
* Accessor for checking whether give {@link DeserializationFeature}
* is enabled or not.
*
* @param feature Feature to check
*
* @return True if feature is enabled; false otherwise
*/
public final boolean isEnabled(DeserializationFeature feature) {
return (_deserFeatures & feature.getMask()) != 0;
}

public final boolean isEnabled(JsonParser.Feature f, JsonFactory factory) {
Expand Down Expand Up @@ -852,7 +868,7 @@ public final int getDeserializationFeatures() {
}

/**
* Convenience method equivalant to:
* Convenience method equivalent to:
*<code>
* isEnabled(DeserializationFeature.FAIL_ON_TRAILING_TOKENS)
*</code>
Expand All @@ -863,6 +879,20 @@ public final boolean requiresFullValue() {
return DeserializationFeature.FAIL_ON_TRAILING_TOKENS.enabledIn(_deserFeatures);
}

/**
* Accessor for checking whether give {@link DatatypeFeature}
* is enabled or not.
*
* @param feature Feature to check
*
* @return True if feature is enabled; false otherwise
*
* @since 2.14
*/
public final boolean isEnabled(DatatypeFeature feature) {
return _datatypeFeatures.isEnabled(feature);
}

/*
/**********************************************************
/* Other configuration
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import com.fasterxml.jackson.databind.cfg.CoercionAction;
import com.fasterxml.jackson.databind.cfg.CoercionInputShape;
import com.fasterxml.jackson.databind.cfg.ContextAttributes;
import com.fasterxml.jackson.databind.cfg.DatatypeFeature;
import com.fasterxml.jackson.databind.deser.*;
import com.fasterxml.jackson.databind.deser.impl.ObjectIdReader;
import com.fasterxml.jackson.databind.deser.impl.ReadableObjectId;
Expand Down Expand Up @@ -276,6 +277,11 @@ public final boolean isEnabled(MapperFeature feature) {
return _config.isEnabled(feature);
}

@Override // @since 2.14
public final boolean isEnabled(DatatypeFeature feature) {
return _config.isEnabled(feature);
}

@Override
public final JsonFormat.Value getDefaultPropertyFormat(Class<?> baseType) {
return _config.getDefaultPropertyFormat(baseType);
Expand Down
35 changes: 29 additions & 6 deletions src/main/java/com/fasterxml/jackson/databind/ObjectMapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -658,10 +658,12 @@ public ObjectMapper(JsonFactory jf,
_configOverrides = new ConfigOverrides();
_coercionConfigs = new CoercionConfigs();
_serializationConfig = new SerializationConfig(base,
_subtypeResolver, mixins, rootNames, _configOverrides);
_subtypeResolver, mixins, rootNames, _configOverrides,
DatatypeFeatures.defaultFeatures());
_deserializationConfig = new DeserializationConfig(base,
_subtypeResolver, mixins, rootNames, _configOverrides,
_coercionConfigs);
_coercionConfigs,
DatatypeFeatures.defaultFeatures());

// Some overrides we may need
final boolean needOrder = _jsonFactory.requiresPropertyOrdering();
Expand Down Expand Up @@ -880,7 +882,7 @@ public boolean isEnabled(MapperFeature f) {
public boolean isEnabled(DeserializationFeature f) {
return ObjectMapper.this.isEnabled(f);
}

@Override
public boolean isEnabled(SerializationFeature f) {
return ObjectMapper.this.isEnabled(f);
Expand Down Expand Up @@ -2569,7 +2571,7 @@ public ObjectMapper disable(SerializationFeature first,
_serializationConfig = _serializationConfig.without(first, f);
return this;
}

/*
/**********************************************************
/* Configuration, simple features: DeserializationFeature
Expand Down Expand Up @@ -2612,7 +2614,7 @@ public ObjectMapper enable(DeserializationFeature first,
_deserializationConfig = _deserializationConfig.with(first, f);
return this;
}

/**
* Method for enabling specified {@link DeserializationConfig} features.
* Modifies and returns this instance; no new object is created.
Expand All @@ -2631,7 +2633,28 @@ public ObjectMapper disable(DeserializationFeature first,
_deserializationConfig = _deserializationConfig.without(first, f);
return this;
}


/*
/**********************************************************
/* Configuration, simple features: DatatypeFeature
/**********************************************************
*/

/**
* Method for changing state of an on/off datatype-specific feature for
* this object mapper.
*/
public ObjectMapper configure(DatatypeFeature f, boolean state) {
if (state) {
_deserializationConfig = _deserializationConfig.with(f);
_serializationConfig = _serializationConfig.with(f);
} else {
_deserializationConfig = _deserializationConfig.without(f);
_serializationConfig = _serializationConfig.without(f);
}
return this;
}

/*
/**********************************************************
/* Configuration, simple features: JsonParser.Feature
Expand Down
54 changes: 54 additions & 0 deletions src/main/java/com/fasterxml/jackson/databind/ObjectReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import com.fasterxml.jackson.core.type.TypeReference;

import com.fasterxml.jackson.databind.cfg.ContextAttributes;
import com.fasterxml.jackson.databind.cfg.DatatypeFeature;
import com.fasterxml.jackson.databind.deser.DataFormatReaders;
import com.fasterxml.jackson.databind.deser.DefaultDeserializationContext;
import com.fasterxml.jackson.databind.deser.DeserializationProblemHandler;
Expand Down Expand Up @@ -435,6 +436,52 @@ public ObjectReader withoutFeatures(DeserializationFeature... features) {
return _with(_config.withoutFeatures(features));
}

/*
/**********************************************************************
/* Life-cycle, fluent factory methods for DatatypeFeatures (2.14+)
/**********************************************************************
*/

/**
* Method for constructing a new reader instance that is configured
* with specified feature enabled.
*
* @since 2.14
*/
public ObjectReader with(DatatypeFeature feature) {
return _with(_config.with(feature));
}

/**
* Method for constructing a new reader instance that is configured
* with specified features enabled.
*
* @since 2.14
*/
public ObjectReader withFeatures(DatatypeFeature... features) {
return _with(_config.withFeatures(features));
}

/**
* Method for constructing a new reader instance that is configured
* with specified feature disabled.
*
* @since 2.14
*/
public ObjectReader without(DatatypeFeature feature) {
return _with(_config.without(feature));
}

/**
* Method for constructing a new reader instance that is configured
* with specified features disabled.
*
* @since 2.14
*/
public ObjectReader withoutFeatures(DatatypeFeature... features) {
return _with(_config.withoutFeatures(features));
}

/*
/**********************************************************
/* Life-cycle, fluent factory methods for JsonParser.Features
Expand Down Expand Up @@ -953,6 +1000,13 @@ public boolean isEnabled(MapperFeature f) {
return _config.isEnabled(f);
}

/**
* @since 2.14
*/
public boolean isEnabled(DatatypeFeature f) {
return _config.isEnabled(f);
}

public boolean isEnabled(JsonParser.Feature f) {
return _config.isEnabled(f, _parserFactory);
}
Expand Down
Loading

0 comments on commit f471dc8

Please sign in to comment.