java.lang.Object
org.sentrysoftware.maven.metricshub.connector.producer.JsonNodeHelper

public class JsonNodeHelper extends Object
Utility class for common operations and methods with JsonNode objects.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static List<String>
    convertSimpleArrayNodeToList(com.fasterxml.jackson.databind.node.ArrayNode arrayNode)
    Converts a Jackson ArrayNode to a List of strings.
    static List<String>
    nodeToStringList(com.fasterxml.jackson.databind.JsonNode node)
    Converts a JsonNode to a list of strings.
    static boolean
    nonNull(com.fasterxml.jackson.databind.JsonNode node)
    Checks if the provided JsonNode is non-null and not a JSON null node.
    static boolean
    nonNullBooleanOrDefault(com.fasterxml.jackson.databind.JsonNode node, boolean defaultValue)
    Returns the boolean value of the provided JsonNode if it is non-null and not a JSON null node.
    static String
    nonNullTextOrDefault(com.fasterxml.jackson.databind.JsonNode node, String defaultValue)
    Returns the text value of the provided JsonNode if it is non-null and not a JSON null node.
    static Stream<com.fasterxml.jackson.databind.JsonNode>
    stream(com.fasterxml.jackson.databind.node.ArrayNode arrayNode)
    Converts an ArrayNode into a filtered Stream of non-null JsonNode elements.

    Methods inherited from class java.lang.Object

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

    • JsonNodeHelper

      public JsonNodeHelper()
  • Method Details

    • nonNull

      public static boolean nonNull(com.fasterxml.jackson.databind.JsonNode node)
      Checks if the provided JsonNode is non-null and not a JSON null node.
      Parameters:
      node - The JsonNode to be checked.
      Returns:
      true if the node is non-null and not a JSON null, false otherwise.
    • stream

      public static Stream<com.fasterxml.jackson.databind.JsonNode> stream(com.fasterxml.jackson.databind.node.ArrayNode arrayNode)
      Converts an ArrayNode into a filtered Stream of non-null JsonNode elements.

      This method transforms the provided ArrayNode into a sequential stream of JsonNode objects, filtering out any null elements from the stream. The resulting stream is ordered and immutable.

      Parameters:
      arrayNode - The ArrayNode to be converted to a Stream.
      Returns:
      A sequential Stream of non-null JsonNode elements extracted from the given ArrayNode.
    • nodeToStringList

      public static List<String> nodeToStringList(com.fasterxml.jackson.databind.JsonNode node)
      Converts a JsonNode to a list of strings.

      This method takes a JsonNode as input and converts it into a list of strings. If the input node is an array, the method uses convertSimpleArrayNodeToList(ArrayNode) to perform the conversion. If the node is a single value node, it is converted into a singleton list containing its text representation. If the input node is null or not of the expected types, an empty list is returned.

      Parameters:
      node - The JsonNode to convert to a list of strings.
      Returns:
      A List of strings representing the contents of the input node, or an empty list if the node is null or not of the expected types.
    • convertSimpleArrayNodeToList

      public static List<String> convertSimpleArrayNodeToList(com.fasterxml.jackson.databind.node.ArrayNode arrayNode)
      Converts a Jackson ArrayNode to a List of strings.
      Parameters:
      arrayNode - The ArrayNode to be converted to a list of strings.
      Returns:
      A List<String> containing the text representations of the elements in the ArrayNode.
      Throws:
      NullPointerException - if arrayNode is null.
    • nonNullTextOrDefault

      public static String nonNullTextOrDefault(com.fasterxml.jackson.databind.JsonNode node, String defaultValue)
      Returns the text value of the provided JsonNode if it is non-null and not a JSON null node. If the node is null or represents a JSON null, the specified default value is returned.
      Parameters:
      node - The JsonNode to extract text from.
      defaultValue - The default value to return if the node is null or represents a JSON null.
      Returns:
      The text value of the JsonNode or the specified default value if the node is null or represents a JSON null.
    • nonNullBooleanOrDefault

      public static boolean nonNullBooleanOrDefault(com.fasterxml.jackson.databind.JsonNode node, boolean defaultValue)
      Returns the boolean value of the provided JsonNode if it is non-null and not a JSON null node. If the node is null or represents a JSON null, the specified default value is returned.
      Parameters:
      node - The JsonNode to extract text from.
      defaultValue - The default value to return if the node is null or represents a JSON null.
      Returns:
      The boolean value of the JsonNode or the specified default value if the node is null or represents a JSON null.