Class JsonUtil

java.lang.Object
com.wontlost.ckeditor.JsonUtil

public final class JsonUtil extends Object
Utility class for JSON operations using Jackson. Provides a shared ObjectMapper instance and common helper methods.

This class centralizes Jackson ObjectMapper usage to:

  • Ensure consistent configuration across the codebase
  • Avoid redundant ObjectMapper instances
  • Provide convenient helper methods for common operations
  • Method Summary

    Modifier and Type
    Method
    Description
    static tools.jackson.databind.node.ArrayNode
    Create a new ArrayNode.
    static tools.jackson.databind.node.ObjectNode
    Create a new ObjectNode.
    static tools.jackson.databind.ObjectMapper
    Get the shared ObjectMapper instance.
    static boolean
    Check if an array is non-null and non-empty.
    static tools.jackson.databind.node.ArrayNode
    Create an ArrayNode from a string array.
    static tools.jackson.databind.node.ArrayNode
    Create an ArrayNode from a string array, only if the array is non-empty.
    static <T> tools.jackson.databind.JsonNode
    valueToTree(T value)
    Convert a value to a JSON tree representation.

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • getMapper

      public static tools.jackson.databind.ObjectMapper getMapper()
      Get the shared ObjectMapper instance. This instance is thread-safe for read operations.
      Returns:
      the shared ObjectMapper
    • createObjectNode

      public static tools.jackson.databind.node.ObjectNode createObjectNode()
      Create a new ObjectNode.
      Returns:
      a new empty ObjectNode
    • createArrayNode

      public static tools.jackson.databind.node.ArrayNode createArrayNode()
      Create a new ArrayNode.
      Returns:
      a new empty ArrayNode
    • valueToTree

      public static <T> tools.jackson.databind.JsonNode valueToTree(T value)
      Convert a value to a JSON tree representation.
      Type Parameters:
      T - the type of the value
      Parameters:
      value - the value to convert
      Returns:
      the JSON tree representation
    • toArrayNode

      public static tools.jackson.databind.node.ArrayNode toArrayNode(String[] items)
      Create an ArrayNode from a string array. Null values in the array are skipped.
      Parameters:
      items - the string array
      Returns:
      an ArrayNode containing the items, or an empty ArrayNode if items is null
    • toArrayNodeOrNull

      public static tools.jackson.databind.node.ArrayNode toArrayNodeOrNull(String[] items)
      Create an ArrayNode from a string array, only if the array is non-empty.
      Parameters:
      items - the string array
      Returns:
      an ArrayNode containing the items, or null if items is null or empty
    • hasElements

      public static boolean hasElements(Object[] items)
      Check if an array is non-null and non-empty.
      Parameters:
      items - the array to check
      Returns:
      true if the array has elements, false otherwise