Class BooleanNode

All Implemented Interfaces:
Serializable, Iterable<JsonNode>, TreeNode, JacksonSerializable

public class BooleanNode extends ValueNode
This concrete value class is used to contain boolean (true / false) values. Only two instances are ever created, to minimize memory usage.
See Also:
  • Field Details

  • Constructor Details

    • BooleanNode

      protected BooleanNode(boolean v)
  • Method Details

    • readResolve

      protected Object readResolve()
    • getTrue

      public static BooleanNode getTrue()
    • getFalse

      public static BooleanNode getFalse()
    • valueOf

      public static BooleanNode valueOf(boolean b)
    • getNodeType

      public JsonNodeType getNodeType()
      Description copied from class: JsonNode
      Return the type of this node
      Specified by:
      getNodeType in class JsonNode
      Returns:
      the node type as a JsonNodeType enum value
    • asToken

      public JsonToken asToken()
      Description copied from class: BaseJsonNode
      Method that can be used for efficient type detection when using stream abstraction for traversing nodes. Will return the first JsonToken that equivalent stream event would produce (for most nodes there is just one token but for structured/container types multiple)
      Specified by:
      asToken in interface TreeNode
      Specified by:
      asToken in class ValueNode
    • _valueDesc

      protected String _valueDesc()
      Description copied from class: BaseJsonNode
      Method for implementation classes to return a short description of contained value, to be used in error messages.
      Specified by:
      _valueDesc in class BaseJsonNode
    • deepCopy

      public BooleanNode deepCopy()
      Description copied from class: ValueNode
      All current value nodes are immutable, so we can just return them as is.
      Overrides:
      deepCopy in class ValueNode
      Returns:
      Node that is either a copy of this node (and all non-leaf children); or, for immutable leaf nodes, node itself.
    • asBoolean

      public final boolean asBoolean()
      Description copied from class: JsonNode
      Method that will try to convert value of this node to a Java boolean. JSON Booleans map naturally; Integer numbers other than 0 map to true, and 0 maps to false; null maps to false and Strings 'true' and 'false' map to corresponding values. Other values (including structured types like Objects and Arrays) will result in a JsonNodeException being thrown.
      Overrides:
      asBoolean in class BaseJsonNode
      Returns:
      Boolean value this node represents, if coercible; exception otherwise
    • asBoolean

      public final boolean asBoolean(boolean defaultValue)
      Description copied from class: JsonNode
      Similar to JsonNode.asBoolean(), but instead of throwing an exception for non-coercible values, will return specified default value.
      Overrides:
      asBoolean in class BaseJsonNode
    • asBooleanOpt

      public Optional<Boolean> asBooleanOpt()
      Description copied from class: JsonNode
      Similar to JsonNode.asBoolean(), but instead of throwing an exception for non-coercible values, will return Optional.empty().
      Overrides:
      asBooleanOpt in class BaseJsonNode
    • _asBoolean

      protected Boolean _asBoolean()
      Description copied from class: BaseJsonNode
      Method sub-classes should override if they can produce boolean values via BaseJsonNode.asBoolean() -- if not, return null (in which case appropriate error will be thrown or default value returned).
      Overrides:
      _asBoolean in class BaseJsonNode
      Returns:
      Coerced value if possible; otherwise null to indicate this node cannot be coerced.
    • booleanValue

      public boolean booleanValue()
      Description copied from class: JsonNode
      Method that will try to access value of this node as a Java boolean which works if (and only if) node contains JSON boolean value: if not, a JsonNodeException will be thrown.

      NOTE: for more lenient conversions, use JsonNode.asBoolean()

      Overrides:
      booleanValue in class BaseJsonNode
      Returns:
      boolean value this node represents (if JSON boolean)
    • booleanValue

      public boolean booleanValue(boolean defaultValue)
      Description copied from class: JsonNode
      Method similar to JsonNode.booleanValue(), but that will return specified defaultValue if this node does not contain a JSON boolean.
      Overrides:
      booleanValue in class BaseJsonNode
      Parameters:
      defaultValue - Value to return if this node does not contain a JSON boolean.
      Returns:
      Java boolean value this node represents (if JSON boolean); defaultValue otherwise
    • booleanValueOpt

      public Optional<Boolean> booleanValueOpt()
      Description copied from class: JsonNode
      Method similar to JsonNode.booleanValue(), but that will return Optional.empty() if this node does not contain a JSON boolean.
      Overrides:
      booleanValueOpt in class BaseJsonNode
      Returns:
      Optional<Boolean> value (if node represents JSON boolean); Optional.empty() otherwise
    • _asString

      protected String _asString()
      Description copied from class: BaseJsonNode
      Method sub-classes should override if they can produce String values via BaseJsonNode.asString() -- if not, return null (in which case appropriate error will be thrown or default value returned).
      Overrides:
      _asString in class BaseJsonNode
      Returns:
      Coerced value if possible; otherwise null to indicate this node cannot be coerced.
    • asLong

      public long asLong(long defaultValue)
      Description copied from class: JsonNode
      Method similar to JsonNode.asLong(), but that will return specified defaultValue if this node cannot be coerced to long (instead of throwing an exception).
      Overrides:
      asLong in class BaseJsonNode
      Parameters:
      defaultValue - Value to return if this node cannot be coerced to long
      Returns:
      long value this node represents, if possible to accurately represent; defaultValue otherwise
    • serialize

      public final void serialize(JsonGenerator g, SerializationContext provider) throws JacksonException
      Description copied from class: BaseJsonNode
      Method called to serialize node instances using given generator.
      Specified by:
      serialize in interface JacksonSerializable
      Specified by:
      serialize in class BaseJsonNode
      Throws:
      JacksonException
    • hashCode

      public int hashCode()
      Specified by:
      hashCode in class BaseJsonNode
    • equals

      public boolean equals(Object o)
      Description copied from class: JsonNode
      Equality for node objects is defined as full (deep) value equality. This means that it is possible to compare complete JSON trees for equality by comparing equality of root nodes.

      Note: marked as abstract to ensure all implementation classes define it properly and not rely on definition from Object.

      Specified by:
      equals in class JsonNode