Class JsonUtilities
-
- All Implemented Interfaces:
public final class JsonUtilitiesJSON-based utility methods for acquiring and working with JSON from files and objects.
Griefed
-
-
Field Summary
Fields Modifier and Type Field Description private final ObjectMapperobjectMapper
-
Constructor Summary
Constructors Constructor Description JsonUtilities(ObjectMapper objectMapper)
-
Method Summary
Modifier and Type Method Description final ObjectMappergetObjectMapper()final BooleannestedTextMatches(JsonNode jsonNode, Regex matches, String childNodes)Check whether the text in specified child node(s) matches the specified text. final StringgetNestedText(JsonNode jsonNode, String childNodes)Get the text from nested child node(s). final JsonNodegetNestedElement(JsonNode jsonNode, String childNodes)Get a nested element from a JsonNode. final BooleannestedTextEqualsIgnoreCase(JsonNode jsonNode, String equalsIgnoreCase, String childNodes)Check whether the text in specified child node(s) is equal to the specified text, case-insensitive. final BooleannestedTextIsEmpty(JsonNode jsonNode, String childNodes)Check whether the text in the specified child node(s) is empty. final BooleangetNestedBoolean(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 BooleannestedTextContains(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 JsonNodegetJson(InputStream inputStream)Acquire a JsonNode from the given json input-stream. final JsonNodegetJson(String string)Acquire a JsonNode from the given json string. final JsonNodegetJson(File file)Acquire a JsonNode from the given json file. final JsonNodegetJson(URL url)Acquire a JsonNode from the given URL. -
-
Method Detail
-
getObjectMapper
final ObjectMapper getObjectMapper()
-
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:
trueif 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:
trueif 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:
trueif 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:
trueorfalse, 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:
trueif 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.
-
-
-
-