Class JsonNode<T>

java.lang.Object
club.someoneice.json.node.JsonNode<T>
All Implemented Interfaces:
NodeLike, Cloneable
Direct Known Subclasses:
ArrayNode, BooleanNode, DoubleNode, FloatNode, IntegerNode, LongNode, MapNode, NullNode, StringNode

public class JsonNode<T> extends Object implements NodeLike, Cloneable
  • Field Details

    • obj

      protected final T obj
  • Constructor Details

    • JsonNode

      public JsonNode(T obj)
  • Method Details

    • getType

      public JsonNode.NodeType getType()
      获取 JsonNode 持有的参形。通常这个方法会被对应属性的 JsonNode 覆写,因此 JsonNode 默认的匹配机制只会在类型持有时被执行一次。
      Specified by:
      getType in interface NodeLike
      Returns:
      JsonNode 持有的数据类型。
    • asTypeNode

      public JsonNode asTypeNode()
      Returns:
      将未知的类型重写为可知类型。
    • asTypeNodeOrThrow

      public JsonNode asTypeNodeOrThrow(JsonNode.NodeType type, String message)
      将未知的类型重写为目标类型。当类型不符时会抛出 NodeCastException 错误以警告。
      Parameters:
      type - 将要检查的目标类型。
      message - 无法匹配时的错误类型。
      Returns:
      持有目标类型的 JsonNode。
      Throws:
      NodeCastException - 当持有类型与目标类型不符合时,抛出错误。
    • asTypeNodeOrThrow

      public JsonNode asTypeNodeOrThrow(JsonNode.NodeType type)
      将未知的类型重写为目标类型。当类型不符时会抛出 NodeCastException 错误以警告。
      Parameters:
      type - 将要检查的目标类型。
      Returns:
      持有目标类型的 JsonNode。
      Throws:
      NodeCastException - 当持有类型与目标类型不符合时,抛出错误。
    • asTypeOrElse

      public <N extends JsonNode> N asTypeOrElse(JsonNode.NodeType type, Supplier<N> function)
      将未知的类型重写为目标类型。当类型不符时会尝试执行 Supplier 取得补偿。
      Parameters:
      type - 将要检查的目标类型。
      function - 在目标不符时,将会调用的补偿器。
      Returns:
      转型后或补偿后的数据。
    • asTypeOrNull

      public JsonNode asTypeOrNull(JsonNode.NodeType type)
      将未知的类型重写为目标类型。当类型不符时会提供 NullNode。
      Parameters:
      type - 将要检查的目标类型。
      Returns:
      转型后的 JsonNode,亦或是 NullNode。
    • asMapNodeOrEmpty

      public MapNode asMapNodeOrEmpty()
      将 JsonNode 转为 MapNode,或提供空的 MapNode。
      Returns:
      转型后的,亦或是空的 MapNode。
    • asArrayNodeOrEmpty

      public ArrayNode asArrayNodeOrEmpty()
      将 JsonNode 转为 ArrayNode,或提供空的 ArrayNode。
      Returns:
      转型后的,亦或是空的 ArrayNode。
    • copy

      public JsonNode<?> copy()
      Returns:
      拷贝数据类型为一个全新对象。返回值不会与原有值存在除内容相同外的交集。
    • typeOf

      public boolean typeOf(JsonNode.NodeType type)
      Parameters:
      type - 期望匹配的 NodeType。
      Returns:
      相同的 NodeType 将会返回 True。
      See Also:
    • isNull

      public boolean isNull()
    • nonNull

      public boolean nonNull()
    • getObj

      public T getObj()
      Returns:
      JsonNode 持有的真实数据。
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • asJsonNode

      public JsonNode asJsonNode()
      Description copied from interface: NodeLike
      保证数据最终能变为 JsonNode。
      Specified by:
      asJsonNode in interface NodeLike
      Returns:
      为目标类创建的 JsonNode 返回值。
    • clone

      protected Object clone() throws CloneNotSupportedException
      Overrides:
      clone in class Object
      Throws:
      CloneNotSupportedException
    • asJsonNodeOrEmpty

      public static JsonNode asJsonNodeOrEmpty(Object obj)