Skip to content

Commit

Permalink
Minor addition DatatypeFeatures for checking explicit enable/disabl…
Browse files Browse the repository at this point in the history
…e settings
  • Loading branch information
cowtowncoder committed Jan 24, 2023
1 parent b0ec175 commit 5f1c405
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,54 @@ public boolean isExplicitlySet(DatatypeFeature f) {
}
}

/**
* Convenience method equivalent to:
*<pre>
* isExplicitlySet(f) && isEnabled(f)
*</pre>
*
* @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:
*<pre>
* isExplicitlySet(f) && isDisabled(f)
*</pre>
*
* @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)
Expand Down
Original file line number Diff line number Diff line change
@@ -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;

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 5f1c405

Please sign in to comment.