Class JacksonConfigNode

java.lang.Object
dev.polv.taleapi.config.json.JacksonConfigNode
All Implemented Interfaces:
ConfigNode

public class JacksonConfigNode extends Object implements ConfigNode
Jackson-based implementation of ConfigNode.
  • Constructor Details

    • JacksonConfigNode

      public JacksonConfigNode(com.fasterxml.jackson.databind.JsonNode node, com.fasterxml.jackson.databind.ObjectMapper mapper)
      Creates a new JacksonConfigNode wrapping the given JsonNode.
      Parameters:
      node - the Jackson JsonNode
      mapper - the ObjectMapper for conversions
  • Method Details

    • getJsonNode

      public com.fasterxml.jackson.databind.JsonNode getJsonNode()
      Returns the underlying Jackson JsonNode.
      Returns:
      the JsonNode
    • isObject

      public boolean isObject()
      Description copied from interface: ConfigNode
      Checks if this node represents a JSON object (key-value pairs).
      Specified by:
      isObject in interface ConfigNode
      Returns:
      true if this node is an object
    • isArray

      public boolean isArray()
      Description copied from interface: ConfigNode
      Checks if this node represents a JSON array.
      Specified by:
      isArray in interface ConfigNode
      Returns:
      true if this node is an array
    • isValue

      public boolean isValue()
      Description copied from interface: ConfigNode
      Checks if this node represents a primitive value (string, number, boolean).
      Specified by:
      isValue in interface ConfigNode
      Returns:
      true if this node is a value
    • isNull

      public boolean isNull()
      Description copied from interface: ConfigNode
      Checks if this node is null or missing.
      Specified by:
      isNull in interface ConfigNode
      Returns:
      true if this node is null
    • has

      public boolean has(String key)
      Description copied from interface: ConfigNode
      Checks if a key exists in this object node.

      Supports dot notation for nested paths: "database.host"

      Specified by:
      has in interface ConfigNode
      Parameters:
      key - the key or path to check
      Returns:
      true if the key exists
    • keys

      public Set<String> keys()
      Description copied from interface: ConfigNode
      Returns all keys in this object node.
      Specified by:
      keys in interface ConfigNode
      Returns:
      set of keys, or empty set if not an object
    • size

      public int size()
      Description copied from interface: ConfigNode
      Returns the number of elements in this node.

      For objects, returns the number of keys. For arrays, returns the number of elements. For values, returns 1.

      Specified by:
      size in interface ConfigNode
      Returns:
      the size of this node
    • get

      public ConfigNode get(String key)
      Description copied from interface: ConfigNode
      Gets a child node by key.

      Supports dot notation for nested paths: "database.host"

      Specified by:
      get in interface ConfigNode
      Parameters:
      key - the key or path
      Returns:
      the child node, or a null node if not found
    • get

      public ConfigNode get(int index)
      Description copied from interface: ConfigNode
      Gets a child node by array index.
      Specified by:
      get in interface ConfigNode
      Parameters:
      index - the array index
      Returns:
      the child node, or a null node if out of bounds
    • getString

      public String getString(String key)
      Description copied from interface: ConfigNode
      Gets a string value by key.
      Specified by:
      getString in interface ConfigNode
      Parameters:
      key - the key or path
      Returns:
      the string value
    • getString

      public String getString(String key, String defaultValue)
      Description copied from interface: ConfigNode
      Gets a string value by key, with a default.
      Specified by:
      getString in interface ConfigNode
      Parameters:
      key - the key or path
      defaultValue - the default value if key doesn't exist
      Returns:
      the string value or default
    • getOptionalString

      public Optional<String> getOptionalString(String key)
      Description copied from interface: ConfigNode
      Gets an optional string value by key.
      Specified by:
      getOptionalString in interface ConfigNode
      Parameters:
      key - the key or path
      Returns:
      an Optional containing the value, or empty if not found
    • getInt

      public int getInt(String key)
      Description copied from interface: ConfigNode
      Gets an integer value by key.
      Specified by:
      getInt in interface ConfigNode
      Parameters:
      key - the key or path
      Returns:
      the integer value
    • getInt

      public int getInt(String key, int defaultValue)
      Description copied from interface: ConfigNode
      Gets an integer value by key, with a default.
      Specified by:
      getInt in interface ConfigNode
      Parameters:
      key - the key or path
      defaultValue - the default value if key doesn't exist
      Returns:
      the integer value or default
    • getOptionalInt

      public Optional<Integer> getOptionalInt(String key)
      Description copied from interface: ConfigNode
      Gets an optional integer value by key.
      Specified by:
      getOptionalInt in interface ConfigNode
      Parameters:
      key - the key or path
      Returns:
      an Optional containing the value, or empty if not found
    • getLong

      public long getLong(String key)
      Description copied from interface: ConfigNode
      Gets a long value by key.
      Specified by:
      getLong in interface ConfigNode
      Parameters:
      key - the key or path
      Returns:
      the long value
    • getLong

      public long getLong(String key, long defaultValue)
      Description copied from interface: ConfigNode
      Gets a long value by key, with a default.
      Specified by:
      getLong in interface ConfigNode
      Parameters:
      key - the key or path
      defaultValue - the default value if key doesn't exist
      Returns:
      the long value or default
    • getOptionalLong

      public Optional<Long> getOptionalLong(String key)
      Description copied from interface: ConfigNode
      Gets an optional long value by key.
      Specified by:
      getOptionalLong in interface ConfigNode
      Parameters:
      key - the key or path
      Returns:
      an Optional containing the value, or empty if not found
    • getDouble

      public double getDouble(String key)
      Description copied from interface: ConfigNode
      Gets a double value by key.
      Specified by:
      getDouble in interface ConfigNode
      Parameters:
      key - the key or path
      Returns:
      the double value
    • getDouble

      public double getDouble(String key, double defaultValue)
      Description copied from interface: ConfigNode
      Gets a double value by key, with a default.
      Specified by:
      getDouble in interface ConfigNode
      Parameters:
      key - the key or path
      defaultValue - the default value if key doesn't exist
      Returns:
      the double value or default
    • getOptionalDouble

      public Optional<Double> getOptionalDouble(String key)
      Description copied from interface: ConfigNode
      Gets an optional double value by key.
      Specified by:
      getOptionalDouble in interface ConfigNode
      Parameters:
      key - the key or path
      Returns:
      an Optional containing the value, or empty if not found
    • getBoolean

      public boolean getBoolean(String key)
      Description copied from interface: ConfigNode
      Gets a boolean value by key.
      Specified by:
      getBoolean in interface ConfigNode
      Parameters:
      key - the key or path
      Returns:
      the boolean value
    • getBoolean

      public boolean getBoolean(String key, boolean defaultValue)
      Description copied from interface: ConfigNode
      Gets a boolean value by key, with a default.
      Specified by:
      getBoolean in interface ConfigNode
      Parameters:
      key - the key or path
      defaultValue - the default value if key doesn't exist
      Returns:
      the boolean value or default
    • getOptionalBoolean

      public Optional<Boolean> getOptionalBoolean(String key)
      Description copied from interface: ConfigNode
      Gets an optional boolean value by key.
      Specified by:
      getOptionalBoolean in interface ConfigNode
      Parameters:
      key - the key or path
      Returns:
      an Optional containing the value, or empty if not found
    • getList

      public List<ConfigNode> getList(String key)
      Description copied from interface: ConfigNode
      Gets a list of child nodes by key.
      Specified by:
      getList in interface ConfigNode
      Parameters:
      key - the key or path
      Returns:
      list of ConfigNode elements
    • getStringList

      public List<String> getStringList(String key)
      Description copied from interface: ConfigNode
      Gets a list of strings by key.
      Specified by:
      getStringList in interface ConfigNode
      Parameters:
      key - the key or path
      Returns:
      list of strings
    • getIntList

      public List<Integer> getIntList(String key)
      Description copied from interface: ConfigNode
      Gets a list of integers by key.
      Specified by:
      getIntList in interface ConfigNode
      Parameters:
      key - the key or path
      Returns:
      list of integers
    • as

      public <T> T as(Class<T> type)
      Description copied from interface: ConfigNode
      Converts this node to a typed object.
      Specified by:
      as in interface ConfigNode
      Type Parameters:
      T - the type
      Parameters:
      type - the class to convert to
      Returns:
      the converted object
    • get

      public <T> T get(String key, Class<T> type)
      Description copied from interface: ConfigNode
      Converts a child node to a typed object.
      Specified by:
      get in interface ConfigNode
      Type Parameters:
      T - the type
      Parameters:
      key - the key or path
      type - the class to convert to
      Returns:
      the converted object
    • rawValue

      public Object rawValue()
      Description copied from interface: ConfigNode
      Gets this node's value as a raw Object.

      Returns:

      • String, Number, Boolean for primitives
      • List for arrays
      • Map for objects
      • null for null nodes
      Specified by:
      rawValue in interface ConfigNode
      Returns:
      the raw value
    • toJson

      public String toJson()
      Description copied from interface: ConfigNode
      Returns the JSON string representation of this node.
      Specified by:
      toJson in interface ConfigNode
      Returns:
      JSON string
    • toPrettyJson

      public String toPrettyJson()
      Description copied from interface: ConfigNode
      Returns the pretty-printed JSON string representation of this node.
      Specified by:
      toPrettyJson in interface ConfigNode
      Returns:
      pretty-printed JSON string
    • toString

      public String toString()
      Overrides:
      toString in class Object