Class BaseJsonNode

  • All Implemented Interfaces:
    TreeNode, JsonSerializable, java.io.Serializable, java.lang.Iterable<JsonNode>
    Direct Known Subclasses:
    ContainerNode, ValueNode

    public abstract class BaseJsonNode
    extends JsonNode
    implements java.io.Serializable
    Abstract base class common to all standard JsonNode implementations. The main addition here is that we declare that sub-classes must implement JsonSerializable. This simplifies object mapping aspects a bit, as no external serializers are needed.

    Since 2.10, all implements have been Serializable.

    See Also:
    Serialized Form
    • Method Detail

      • findPath

        public final JsonNode findPath​(java.lang.String fieldName)
        Description copied from class: JsonNode
        Method similar to JsonNode.findValue(java.lang.String), but that will return a "missing node" instead of null if no field is found. Missing node is a specific kind of node for which JsonNode.isMissingNode() returns true; and all value access methods return empty or missing value.
        Specified by:
        findPath in class JsonNode
        Parameters:
        fieldName - Name of field to look for
        Returns:
        Value of first matching node found; or if not found, a "missing node" (non-null instance that has no value)
      • hashCode

        public abstract int hashCode()
        Overrides:
        hashCode in class java.lang.Object
      • required

        public JsonNode required​(java.lang.String fieldName)
        Description copied from class: JsonNode
        Method is functionally equivalent to path(fieldName).required() and can be used to check that this node is an ObjectNode (that is, represents JSON Object value) and has value for specified property with key fieldName (but note that value may be explicit JSON null value). If this node is Object Node and has value for specified property, matching value is returned; otherwise IllegalArgumentException is thrown.
        Overrides:
        required in class JsonNode
        Parameters:
        fieldName - Name of property to access
        Returns:
        Value of the specified property of this Object node
      • required

        public JsonNode required​(int index)
        Description copied from class: JsonNode
        Method is functionally equivalent to path(index).required() and can be used to check that this node is an ArrayNode (that is, represents JSON Array value) and has value for specified index (but note that value may be explicit JSON null value). If this node is Array Node and has value for specified index, value at index is returned; otherwise IllegalArgumentException is thrown.
        Overrides:
        required in class JsonNode
        Parameters:
        index - Index of the value of this Array node to access
        Returns:
        Value at specified index of this Array node
      • asToken

        public abstract JsonToken asToken()
        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
        Returns:
        JsonToken that is most closely associated with the node type
      • numberType

        public JsonParser.NumberType numberType()
        Returns code that identifies type of underlying numeric value, if (and only if) node is a number node.
        Specified by:
        numberType in interface TreeNode
        Returns:
        Type of number contained, if any; or null if node does not contain numeric value.
      • toString

        public java.lang.String toString()
        Description copied from class: JsonNode
        Method that will produce (as of Jackson 2.10) valid JSON using default settings of databind, as String. If you want other kinds of JSON output (or output formatted using one of other Jackson-supported data formats) make sure to use ObjectMapper or ObjectWriter to serialize an instance, for example:
           String json = objectMapper.writeValueAsString(rootNode);
        

        Note: method defined as abstract to ensure all implementation classes explicitly implement method, instead of relying on Object.toString() definition.

        Specified by:
        toString in class JsonNode
      • toPrettyString

        public java.lang.String toPrettyString()
        Description copied from class: JsonNode
        Alternative to JsonNode.toString() that will serialize this node using Jackson default pretty-printer.
        Overrides:
        toPrettyString in class JsonNode