Class JsonUtil
java.lang.Object
com.wontlost.ckeditor.JsonUtil
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 TypeMethodDescriptionstatic tools.jackson.databind.node.ArrayNodeCreate a new ArrayNode.static tools.jackson.databind.node.ObjectNodeCreate a new ObjectNode.static tools.jackson.databind.ObjectMapperGet the shared ObjectMapper instance.static booleanhasElements(Object[] items) Check if an array is non-null and non-empty.static tools.jackson.databind.node.ArrayNodetoArrayNode(String[] items) Create an ArrayNode from a string array.static tools.jackson.databind.node.ArrayNodetoArrayNodeOrNull(String[] items) Create an ArrayNode from a string array, only if the array is non-empty.static <T> tools.jackson.databind.JsonNodevalueToTree(T value) Convert a value to a JSON tree representation.
-
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
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
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
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
-