Class JsonOps

java.lang.Object
com.github.darksoulq.abyssallib.common.serialization.DynamicOps<com.fasterxml.jackson.databind.JsonNode>
com.github.darksoulq.abyssallib.common.serialization.ops.JsonOps

public class JsonOps extends DynamicOps<com.fasterxml.jackson.databind.JsonNode>
A DynamicOps implementation backed by Jackson's JsonNode tree model.

This implementation allows codecs to serialize and deserialize structured data into standard JSON representations using Jackson's immutable tree API.

  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final JsonOps
    Singleton instance of JsonOps.
    final com.fasterxml.jackson.databind.ObjectMapper
    Underlying Jackson object mapper used for JSON operations.
  • Method Summary

    Modifier and Type
    Method
    Description
    com.fasterxml.jackson.databind.JsonNode
    copy(com.fasterxml.jackson.databind.JsonNode input)
    Creates a deep copy of the JSON node.
    com.fasterxml.jackson.databind.JsonNode
    createBoolean(boolean value)
    Creates a JSON boolean node.
    com.fasterxml.jackson.databind.JsonNode
    createByte(byte value)
    Creates a JSON numeric node representing a byte.
    com.fasterxml.jackson.databind.JsonNode
    createDouble(double value)
    Creates a JSON numeric node representing a double.
    com.fasterxml.jackson.databind.JsonNode
    createFloat(float value)
    Creates a JSON numeric node representing a float.
    com.fasterxml.jackson.databind.JsonNode
    createInt(int value)
    Creates a JSON numeric node representing an int.
    com.fasterxml.jackson.databind.JsonNode
    createList(List<com.fasterxml.jackson.databind.JsonNode> elements)
    Creates a JSON array node from a list of elements.
    com.fasterxml.jackson.databind.JsonNode
    createLong(long value)
    Creates a JSON numeric node representing a long.
    com.fasterxml.jackson.databind.JsonNode
    createMap(Map<com.fasterxml.jackson.databind.JsonNode, com.fasterxml.jackson.databind.JsonNode> map)
    Creates a JSON object node from a map of key-value pairs.
    com.fasterxml.jackson.databind.JsonNode
    createShort(short value)
    Creates a JSON numeric node representing a short.
    com.fasterxml.jackson.databind.JsonNode
    Creates a JSON string node.
    com.fasterxml.jackson.databind.JsonNode
    Returns the representation of an empty JSON value.
    getBooleanValue(com.fasterxml.jackson.databind.JsonNode input)
    Extracts a boolean value from a JSON node if it is boolean.
    getDoubleValue(com.fasterxml.jackson.databind.JsonNode input)
    Extracts a double value from a JSON node if it is numeric.
    getFloatValue(com.fasterxml.jackson.databind.JsonNode input)
    Extracts a float value from a JSON node if it is numeric.
    getIntValue(com.fasterxml.jackson.databind.JsonNode input)
    Extracts an integer value from a JSON node if it is numeric.
    getKeys(com.fasterxml.jackson.databind.JsonNode input)
    Returns the keys of a JSON object node.
    Optional<List<com.fasterxml.jackson.databind.JsonNode>>
    getList(com.fasterxml.jackson.databind.JsonNode input)
    Converts a JSON array node into a list of JSON nodes.
    getLongValue(com.fasterxml.jackson.databind.JsonNode input)
    Extracts a long value from a JSON node if it is numeric.
    Optional<Map<com.fasterxml.jackson.databind.JsonNode, com.fasterxml.jackson.databind.JsonNode>>
    getMap(com.fasterxml.jackson.databind.JsonNode input)
    Converts a JSON object node into a map of JSON nodes.
    getNumberValue(com.fasterxml.jackson.databind.JsonNode input)
    Extracts a numeric value from a JSON node if it is numeric.
    getStringValue(com.fasterxml.jackson.databind.JsonNode input)
    Extracts a string value from a JSON node if it is textual.
    size(com.fasterxml.jackson.databind.JsonNode input)
    Returns the number of elements in a JSON container node.

    Methods inherited from class Object

    equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • INSTANCE

      public static final JsonOps INSTANCE
      Singleton instance of JsonOps.
    • mapper

      public final com.fasterxml.jackson.databind.ObjectMapper mapper
      Underlying Jackson object mapper used for JSON operations.
  • Method Details

    • createString

      public com.fasterxml.jackson.databind.JsonNode createString(String value)
      Creates a JSON string node.
      Specified by:
      createString in class DynamicOps<com.fasterxml.jackson.databind.JsonNode>
      Parameters:
      value - the string value
      Returns:
      a TextNode containing the value
    • createByte

      public com.fasterxml.jackson.databind.JsonNode createByte(byte value)
      Creates a JSON numeric node representing a byte.
      Specified by:
      createByte in class DynamicOps<com.fasterxml.jackson.databind.JsonNode>
      Parameters:
      value - the byte value
      Returns:
      an IntNode
    • createShort

      public com.fasterxml.jackson.databind.JsonNode createShort(short value)
      Creates a JSON numeric node representing a short.
      Specified by:
      createShort in class DynamicOps<com.fasterxml.jackson.databind.JsonNode>
      Parameters:
      value - the short value
      Returns:
      an IntNode
    • createInt

      public com.fasterxml.jackson.databind.JsonNode createInt(int value)
      Creates a JSON numeric node representing an int.
      Specified by:
      createInt in class DynamicOps<com.fasterxml.jackson.databind.JsonNode>
      Parameters:
      value - the int value
      Returns:
      an IntNode
    • createLong

      public com.fasterxml.jackson.databind.JsonNode createLong(long value)
      Creates a JSON numeric node representing a long.
      Specified by:
      createLong in class DynamicOps<com.fasterxml.jackson.databind.JsonNode>
      Parameters:
      value - the long value
      Returns:
      a LongNode
    • createFloat

      public com.fasterxml.jackson.databind.JsonNode createFloat(float value)
      Creates a JSON numeric node representing a float.
      Specified by:
      createFloat in class DynamicOps<com.fasterxml.jackson.databind.JsonNode>
      Parameters:
      value - the float value
      Returns:
      a FloatNode
    • createDouble

      public com.fasterxml.jackson.databind.JsonNode createDouble(double value)
      Creates a JSON numeric node representing a double.
      Specified by:
      createDouble in class DynamicOps<com.fasterxml.jackson.databind.JsonNode>
      Parameters:
      value - the double value
      Returns:
      a DoubleNode
    • createBoolean

      public com.fasterxml.jackson.databind.JsonNode createBoolean(boolean value)
      Creates a JSON boolean node.
      Specified by:
      createBoolean in class DynamicOps<com.fasterxml.jackson.databind.JsonNode>
      Parameters:
      value - the boolean value
      Returns:
      a BooleanNode
    • createList

      public com.fasterxml.jackson.databind.JsonNode createList(List<com.fasterxml.jackson.databind.JsonNode> elements)
      Creates a JSON array node from a list of elements.
      Specified by:
      createList in class DynamicOps<com.fasterxml.jackson.databind.JsonNode>
      Parameters:
      elements - the list of JSON nodes
      Returns:
      an ArrayNode
    • createMap

      public com.fasterxml.jackson.databind.JsonNode createMap(Map<com.fasterxml.jackson.databind.JsonNode, com.fasterxml.jackson.databind.JsonNode> map)
      Creates a JSON object node from a map of key-value pairs.

      Keys are converted to strings using JsonNode.asText().

      Specified by:
      createMap in class DynamicOps<com.fasterxml.jackson.databind.JsonNode>
      Parameters:
      map - the map of JSON nodes
      Returns:
      an ObjectNode
    • getStringValue

      public Optional<String> getStringValue(com.fasterxml.jackson.databind.JsonNode input)
      Extracts a string value from a JSON node if it is textual.
      Specified by:
      getStringValue in class DynamicOps<com.fasterxml.jackson.databind.JsonNode>
      Parameters:
      input - the JSON node
      Returns:
      the string value if present
    • getNumberValue

      public Optional<Number> getNumberValue(com.fasterxml.jackson.databind.JsonNode input)
      Extracts a numeric value from a JSON node if it is numeric.
      Specified by:
      getNumberValue in class DynamicOps<com.fasterxml.jackson.databind.JsonNode>
      Parameters:
      input - the JSON node
      Returns:
      the number value if present
    • getIntValue

      public Optional<Integer> getIntValue(com.fasterxml.jackson.databind.JsonNode input)
      Extracts an integer value from a JSON node if it is numeric.
      Specified by:
      getIntValue in class DynamicOps<com.fasterxml.jackson.databind.JsonNode>
      Parameters:
      input - the JSON node
      Returns:
      the integer value if present
    • getLongValue

      public Optional<Long> getLongValue(com.fasterxml.jackson.databind.JsonNode input)
      Extracts a long value from a JSON node if it is numeric.
      Specified by:
      getLongValue in class DynamicOps<com.fasterxml.jackson.databind.JsonNode>
      Parameters:
      input - the JSON node
      Returns:
      the long value if present
    • getFloatValue

      public Optional<Float> getFloatValue(com.fasterxml.jackson.databind.JsonNode input)
      Extracts a float value from a JSON node if it is numeric.
      Specified by:
      getFloatValue in class DynamicOps<com.fasterxml.jackson.databind.JsonNode>
      Parameters:
      input - the JSON node
      Returns:
      the float value if present
    • getDoubleValue

      public Optional<Double> getDoubleValue(com.fasterxml.jackson.databind.JsonNode input)
      Extracts a double value from a JSON node if it is numeric.
      Specified by:
      getDoubleValue in class DynamicOps<com.fasterxml.jackson.databind.JsonNode>
      Parameters:
      input - the JSON node
      Returns:
      the double value if present
    • getBooleanValue

      public Optional<Boolean> getBooleanValue(com.fasterxml.jackson.databind.JsonNode input)
      Extracts a boolean value from a JSON node if it is boolean.
      Specified by:
      getBooleanValue in class DynamicOps<com.fasterxml.jackson.databind.JsonNode>
      Parameters:
      input - the JSON node
      Returns:
      the boolean value if present
    • getList

      public Optional<List<com.fasterxml.jackson.databind.JsonNode>> getList(com.fasterxml.jackson.databind.JsonNode input)
      Converts a JSON array node into a list of JSON nodes.
      Specified by:
      getList in class DynamicOps<com.fasterxml.jackson.databind.JsonNode>
      Parameters:
      input - the JSON node
      Returns:
      the list of elements if the node is an array
    • getMap

      public Optional<Map<com.fasterxml.jackson.databind.JsonNode, com.fasterxml.jackson.databind.JsonNode>> getMap(com.fasterxml.jackson.databind.JsonNode input)
      Converts a JSON object node into a map of JSON nodes.
      Specified by:
      getMap in class DynamicOps<com.fasterxml.jackson.databind.JsonNode>
      Parameters:
      input - the JSON node
      Returns:
      the map of entries if the node is an object
    • getKeys

      public Optional<Iterable<String>> getKeys(com.fasterxml.jackson.databind.JsonNode input)
      Returns the keys of a JSON object node.
      Specified by:
      getKeys in class DynamicOps<com.fasterxml.jackson.databind.JsonNode>
      Parameters:
      input - the JSON node
      Returns:
      an iterable of field names if the node is an object
    • size

      public OptionalInt size(com.fasterxml.jackson.databind.JsonNode input)
      Returns the number of elements in a JSON container node.
      Specified by:
      size in class DynamicOps<com.fasterxml.jackson.databind.JsonNode>
      Parameters:
      input - the JSON node
      Returns:
      the size if the node is a container
    • copy

      public com.fasterxml.jackson.databind.JsonNode copy(com.fasterxml.jackson.databind.JsonNode input)
      Creates a deep copy of the JSON node.
      Specified by:
      copy in class DynamicOps<com.fasterxml.jackson.databind.JsonNode>
      Parameters:
      input - the JSON node
      Returns:
      a deep-copied node
    • empty

      public com.fasterxml.jackson.databind.JsonNode empty()
      Returns the representation of an empty JSON value.
      Specified by:
      empty in class DynamicOps<com.fasterxml.jackson.databind.JsonNode>
      Returns:
      NullNode.instance