Class JsonUtilities

  • All Implemented Interfaces:

    
    public final class JsonUtilities
    
                        

    JSON-based utility methods for acquiring and working with JSON from files and objects.

    Author:

    Griefed

    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private final ObjectMapper objectMapper
    • Constructor Summary

      Constructors 
      Constructor Description
      JsonUtilities(ObjectMapper objectMapper)
    • Enum Constant Summary

      Enum Constants 
      Enum Constant Description
    • Method Summary

      Modifier and Type Method Description
      final ObjectMapper getObjectMapper()
      final Boolean nestedTextMatches(JsonNode jsonNode, Regex matches, String childNodes) Check whether the text in specified child node(s) matches the specified text.
      final String getNestedText(JsonNode jsonNode, String childNodes) Get the text from nested child node(s).
      final JsonNode getNestedElement(JsonNode jsonNode, String childNodes) Get a nested element from a JsonNode.
      final Boolean nestedTextEqualsIgnoreCase(JsonNode jsonNode, String equalsIgnoreCase, String childNodes) Check whether the text in specified child node(s) is equal to the specified text, case-insensitive.
      final Boolean nestedTextIsEmpty(JsonNode jsonNode, String childNodes) Check whether the text in the specified child node(s) is empty.
      final Boolean getNestedBoolean(JsonNode jsonNode, String childNodes) Get the boolean value from the nested child node(s).
      final Array<String> getNestedTexts(JsonNode jsonNode, String split, String childNodes) Get the array of texts from the nested child node(s) comma-separated text.
      final Boolean nestedTextContains(JsonNode jsonNode, String contains, String childNodes) Check whether a child node contains the specified text.
      final Iterator<String> getFieldNames(JsonNode jsonNode, String childNodes) Get a string iterator for the field names of the last specified child node in the specified JsonNode.
      final JsonNode getJson(InputStream inputStream) Acquire a JsonNode from the given json input-stream.
      final JsonNode getJson(String string) Acquire a JsonNode from the given json string.
      final JsonNode getJson(File file) Acquire a JsonNode from the given json file.
      final JsonNode getJson(URL url) Acquire a JsonNode from the given URL.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • JsonUtilities

        JsonUtilities(ObjectMapper objectMapper)
        Parameters:
        objectMapper - Used for JSON-parsing.
    • Method Detail

      • nestedTextMatches

         final Boolean nestedTextMatches(JsonNode jsonNode, Regex matches, String childNodes)

        Check whether the text in specified child node(s) matches the specified text.

        Parameters:
        jsonNode - The JsonNode from which to acquire the text.
        matches - The text to check for a match.
        childNodes - The nested nodes in the JsonNode to acquire the text from, in order.
        Returns:

        true if the texts match.

      • getNestedText

         final String getNestedText(JsonNode jsonNode, String childNodes)

        Get the text from nested child node(s).

        Parameters:
        jsonNode - The JsonNode from which to acquire the text from.
        childNodes - The child nodes which contain the requested text, in order.
        Returns:

        The text from the requested child node(s).

      • getNestedElement

         final JsonNode getNestedElement(JsonNode jsonNode, String childNodes)

        Get a nested element from a JsonNode.

        Parameters:
        jsonNode - The JsonNode from which to acquire the nested element.
        childNodes - The nested elements, in order.
        Returns:

        The nested element from the JsonNode.

      • nestedTextEqualsIgnoreCase

         final Boolean nestedTextEqualsIgnoreCase(JsonNode jsonNode, String equalsIgnoreCase, String childNodes)

        Check whether the text in specified child node(s) is equal to the specified text, case-insensitive.

        Parameters:
        jsonNode - The JsonNode from which to acquire the text.
        equalsIgnoreCase - The text to check with whether it is equal, case-insensitive.
        childNodes - The nested nodes in the JsonNode to acquire the text from, in order.
        Returns:

        true if the texts are equal, case-insensitive.

      • nestedTextIsEmpty

         final Boolean nestedTextIsEmpty(JsonNode jsonNode, String childNodes)

        Check whether the text in the specified child node(s) is empty.

        Parameters:
        jsonNode - The JsonNode from which to acquire the text.
        childNodes - The nested nodes in the JsonNode to acquire the text from, in order.
        Returns:

        true if the text in the requested node is empty.

      • getNestedBoolean

         final Boolean getNestedBoolean(JsonNode jsonNode, String childNodes)

        Get the boolean value from the nested child node(s).

        Parameters:
        jsonNode - The JsonNode from which to acquire the boolean.
        childNodes - The nested nodes in the JsonNode to acquire the boolean from, in order.
        Returns:

        true or false, based on the boolean in the specified child node(s).

      • getNestedTexts

         final Array<String> getNestedTexts(JsonNode jsonNode, String split, String childNodes)

        Get the array of texts from the nested child node(s) comma-separated text.

        Parameters:
        jsonNode - The JsonNode from which to acquire the texts from.
        split - The character by which to split the text of the last child node into an array with.
        childNodes - The nested nodes in the JsonNode to acquire the texts from, in order.
        Returns:

        An array of strings containing the texts from the specified node(s)

      • nestedTextContains

         final Boolean nestedTextContains(JsonNode jsonNode, String contains, String childNodes)

        Check whether a child node contains the specified text.

        Parameters:
        jsonNode - The JsonNode from which to acquire the text for checks.
        contains - The text to check with whether the node contains it.
        childNodes - The child node(s) from which to acquire the text for contain-checks from, in order.
        Returns:

        true if the child node contains the specified text.

      • getFieldNames

         final Iterator<String> getFieldNames(JsonNode jsonNode, String childNodes)

        Get a string iterator for the field names of the last specified child node in the specified JsonNode.

        Parameters:
        jsonNode - The JsonNode from which to get the string iterator.
        childNodes - The nested nodes from which to get the iterator, in order.
        Returns:

        A string iterator for the field names in the last requested child node in the provided JsonNode.

      • getJson

         final JsonNode getJson(InputStream inputStream)

        Acquire a JsonNode from the given json input-stream.

        Parameters:
        inputStream - The input-stream to read.
        Returns:

        JSON data from the specified file.

      • getJson

         final JsonNode getJson(String string)

        Acquire a JsonNode from the given json string.

        Parameters:
        string - The string to read.
        Returns:

        JSON data from the specified file.

      • getJson

         final JsonNode getJson(File file)

        Acquire a JsonNode from the given json file.

        Parameters:
        file - The file to read.
        Returns:

        JSON data from the specified file.

      • getJson

         final JsonNode getJson(URL url)

        Acquire a JsonNode from the given URL.

        Parameters:
        url - URL to the data which contains your JSON.
        Returns:

        JSON data from the specified file.