diff --git a/src/main/java/com/fasterxml/jackson/databind/cfg/DatatypeFeatures.java b/src/main/java/com/fasterxml/jackson/databind/cfg/DatatypeFeatures.java index c9d0379f22..dbdcb6c92d 100644 --- a/src/main/java/com/fasterxml/jackson/databind/cfg/DatatypeFeatures.java +++ b/src/main/java/com/fasterxml/jackson/databind/cfg/DatatypeFeatures.java @@ -208,6 +208,54 @@ public boolean isExplicitlySet(DatatypeFeature f) { } } + /** + * Convenience method equivalent to: + *
+ * isExplicitlySet(f) && isEnabled(f) + *+ * + * @param f Feature to check + * + * @return Whether given feature has been explicitly enabled + * + * @since 2.15 + */ + public boolean isExplicitlyEnabled(DatatypeFeature f) { + switch (f.featureIndex()) { + case 0: + return f.enabledIn(_explicitFor1 & _enabledFor1); + case 1: + return f.enabledIn(_explicitFor2 & _enabledFor2); + default: + VersionUtil.throwInternal(); + return false; + } + } + + /** + * Convenience method equivalent to: + *
+ * isExplicitlySet(f) && isDisabled(f) + *+ * + * @param f Feature to check + * + * @return Whether given feature has been explicitly disabled + * + * @since 2.15 + */ + public boolean isExplicitlyDisabled(DatatypeFeature f) { + switch (f.featureIndex()) { + case 0: + return f.enabledIn(_explicitFor1 & ~_enabledFor1); + case 1: + return f.enabledIn(_explicitFor2 & ~_enabledFor2); + default: + VersionUtil.throwInternal(); + return false; + } + } + /** * Accessor for getting explicit state of given feature in this set * iff explicitly set, or {@code null} if not explicitly set (default value) diff --git a/src/test/java/com/fasterxml/jackson/databind/node/NodeFeaturesTest.java b/src/test/java/com/fasterxml/jackson/databind/node/NodeFeaturesTest.java index bb8703fe10..109e4d2b18 100644 --- a/src/test/java/com/fasterxml/jackson/databind/node/NodeFeaturesTest.java +++ b/src/test/java/com/fasterxml/jackson/databind/node/NodeFeaturesTest.java @@ -1,6 +1,7 @@ package com.fasterxml.jackson.databind.node; import com.fasterxml.jackson.databind.*; +import com.fasterxml.jackson.databind.cfg.DatatypeFeatures; import com.fasterxml.jackson.databind.cfg.JsonNodeFeature; import com.fasterxml.jackson.databind.json.JsonMapper; @@ -30,6 +31,29 @@ public void testDefaultSettings() throws Exception .isEnabled(JsonNodeFeature.WRITE_NULL_PROPERTIES)); } + public void testImplicitVsExplicit() + { + DatatypeFeatures dfs = DatatypeFeatures.defaultFeatures(); + assertTrue(dfs.isEnabled(JsonNodeFeature.READ_NULL_PROPERTIES)); + assertFalse(dfs.isExplicitlySet(JsonNodeFeature.READ_NULL_PROPERTIES)); + assertFalse(dfs.isExplicitlyEnabled(JsonNodeFeature.READ_NULL_PROPERTIES)); + assertFalse(dfs.isExplicitlyDisabled(JsonNodeFeature.READ_NULL_PROPERTIES)); + + // disable + dfs = dfs.without(JsonNodeFeature.READ_NULL_PROPERTIES); + assertFalse(dfs.isEnabled(JsonNodeFeature.READ_NULL_PROPERTIES)); + assertTrue(dfs.isExplicitlySet(JsonNodeFeature.READ_NULL_PROPERTIES)); + assertFalse(dfs.isExplicitlyEnabled(JsonNodeFeature.READ_NULL_PROPERTIES)); + assertTrue(dfs.isExplicitlyDisabled(JsonNodeFeature.READ_NULL_PROPERTIES)); + + // re-enable + dfs = dfs.with(JsonNodeFeature.READ_NULL_PROPERTIES); + assertTrue(dfs.isEnabled(JsonNodeFeature.READ_NULL_PROPERTIES)); + assertTrue(dfs.isExplicitlySet(JsonNodeFeature.READ_NULL_PROPERTIES)); + assertTrue(dfs.isExplicitlyEnabled(JsonNodeFeature.READ_NULL_PROPERTIES)); + assertFalse(dfs.isExplicitlyDisabled(JsonNodeFeature.READ_NULL_PROPERTIES)); + } + /* /********************************************************************** /* ObjectNode property handling