public final class JsonHelper extends Object
| Constructor and Description |
|---|
JsonHelper() |
| Modifier and Type | Method and Description |
|---|---|
static com.fasterxml.jackson.databind.JsonNode |
addAttribute(com.fasterxml.jackson.databind.JsonNode jsonNode,
String attributeName,
com.fasterxml.jackson.databind.JsonNode newAttriute)
will remove an attribute from the given jsonNode
|
static com.fasterxml.jackson.databind.JsonNode |
addAttributeToArray(com.fasterxml.jackson.databind.JsonNode jsonArray,
com.fasterxml.jackson.databind.JsonNode newAttriute)
will remove an attribute from the given jsonNode
|
static <T extends com.fasterxml.jackson.databind.node.ObjectNode> |
copyResourceToObject(com.fasterxml.jackson.databind.JsonNode resource,
Class<T> type)
creates a new instance of the given type and moves the content from the resource into the new node
|
static Optional<com.fasterxml.jackson.databind.node.ArrayNode> |
getArrayAttribute(com.fasterxml.jackson.databind.JsonNode jsonNode,
String name)
tries to get an array from the given json node
|
static Optional<com.fasterxml.jackson.databind.node.ObjectNode> |
getObjectAttribute(com.fasterxml.jackson.databind.JsonNode jsonNode,
String name)
tries to get an json object from the given json node
|
static Optional<String> |
getSimpleAttribute(com.fasterxml.jackson.databind.JsonNode jsonNode,
String name)
will get a string attribute with the given name from the given json node
|
static <T> Optional<T> |
getSimpleAttribute(com.fasterxml.jackson.databind.JsonNode jsonNode,
String name,
Class<T> type)
will get a string attribute with the given name from the given json node
|
static Optional<List<String>> |
getSimpleAttributeArray(com.fasterxml.jackson.databind.JsonNode jsonNode,
String attributeName)
extracts a list of simple attributes from the given json node
|
static <T> Optional<List<T>> |
getSimpleAttributeArray(com.fasterxml.jackson.databind.JsonNode jsonNode,
String attributeName,
Class<T> type)
extracts a list of simple attributes from the given json node
|
static Optional<com.fasterxml.jackson.databind.JsonNode> |
getSimpleAttributeByName(com.fasterxml.jackson.databind.JsonNode jsonNode,
String attributeName)
will extract a scim attribute by its scim-name.
|
static boolean |
isEmpty(com.fasterxml.jackson.databind.JsonNode jsonNode)
override method for usage with wildfly 18 that still uses jackson 2.9.x
|
static boolean |
isValidJson(String json)
validates if the given string structure is valid json or not
|
static com.fasterxml.jackson.databind.JsonNode |
loadJsonDocument(File file)
will read a json document from a file
|
static <T extends com.fasterxml.jackson.databind.node.ObjectNode> |
loadJsonDocument(File file,
Class<T> type)
will read a json document from a file
|
static com.fasterxml.jackson.databind.JsonNode |
loadJsonDocument(String classPathLocation)
will read a json document from the classpath
|
static <T extends com.fasterxml.jackson.databind.node.ObjectNode> |
loadJsonDocument(String classPathLocation,
Class<T> type)
will read a json document from the classpath
|
static com.fasterxml.jackson.databind.JsonNode |
readJsonDocument(String jsonDocument)
will read a json document from the given string
|
static <T extends com.fasterxml.jackson.databind.node.ObjectNode> |
readJsonDocument(String jsonDocument,
Class<T> type)
will read a json document from the given string
|
static com.fasterxml.jackson.databind.JsonNode |
removeAttribute(com.fasterxml.jackson.databind.JsonNode jsonNode,
String attributeName)
will remove an attribute from the given jsonNode
|
static com.fasterxml.jackson.databind.JsonNode |
removeSimpleAttributeFromArray(com.fasterxml.jackson.databind.JsonNode jsonNode,
String value)
will remove a simple value from a simple array node in the given json document
|
static com.fasterxml.jackson.databind.JsonNode |
replaceNode(com.fasterxml.jackson.databind.JsonNode jsonNode,
String attributeName,
com.fasterxml.jackson.databind.JsonNode replaceNode)
will remove an attribute from the given jsonNode
|
static String |
toJsonString(com.fasterxml.jackson.databind.JsonNode jsonNode)
override method for usage with wildfly 18 that still uses jackson 2.9.x
|
static String |
toPrettyJsonString(com.fasterxml.jackson.databind.JsonNode jsonNode)
override method for usage with wildfly 18 that still uses jackson 2.9.x
|
static <T> com.fasterxml.jackson.databind.JsonNode |
writeValue(com.fasterxml.jackson.databind.JsonNode jsonNode,
String attributeName,
T value)
will remove an attribute from the given jsonNode
|
public static com.fasterxml.jackson.databind.JsonNode loadJsonDocument(String classPathLocation)
classPathLocation - the location of the documentpublic static <T extends com.fasterxml.jackson.databind.node.ObjectNode> T loadJsonDocument(String classPathLocation, Class<T> type)
classPathLocation - the location of the documentpublic static <T extends com.fasterxml.jackson.databind.node.ObjectNode> T loadJsonDocument(File file, Class<T> type)
file - the location of the documentpublic static com.fasterxml.jackson.databind.JsonNode loadJsonDocument(File file)
file - the location of the documentpublic static com.fasterxml.jackson.databind.JsonNode readJsonDocument(String jsonDocument)
jsonDocument - the direct json representationpublic static <T extends com.fasterxml.jackson.databind.node.ObjectNode> T readJsonDocument(String jsonDocument, Class<T> type)
jsonDocument - the direct json representationpublic static Optional<com.fasterxml.jackson.databind.node.ArrayNode> getArrayAttribute(com.fasterxml.jackson.databind.JsonNode jsonNode, String name)
jsonNode - the json node from which the array should be extractedname - the name of the json array attributepublic static Optional<com.fasterxml.jackson.databind.node.ObjectNode> getObjectAttribute(com.fasterxml.jackson.databind.JsonNode jsonNode, String name)
jsonNode - the json node from which the json object should be extractedname - the name of the json object attributepublic static Optional<List<String>> getSimpleAttributeArray(com.fasterxml.jackson.databind.JsonNode jsonNode, String attributeName)
jsonNode - the json document containing an array with simple attributesattributeName - the name of the attribute that is an array with simple attributespublic static <T> Optional<List<T>> getSimpleAttributeArray(com.fasterxml.jackson.databind.JsonNode jsonNode, String attributeName, Class<T> type)
jsonNode - the json document containing an array with simple attributesattributeName - the name of the attribute that is an array with simple attributestype - the type of the values within the arraypublic static Optional<String> getSimpleAttribute(com.fasterxml.jackson.databind.JsonNode jsonNode, String name)
jsonNode - the json node to get the attribute fromname - the name of the attributepublic static <T> Optional<T> getSimpleAttribute(com.fasterxml.jackson.databind.JsonNode jsonNode, String name, Class<T> type)
jsonNode - the json node to get the attribute fromname - the name of the attributetype - the type of the attribute to returnpublic static com.fasterxml.jackson.databind.JsonNode removeAttribute(com.fasterxml.jackson.databind.JsonNode jsonNode,
String attributeName)
jsonNode - the json node from which the attribute should be removedattributeName - the name of the attribute to removepublic static com.fasterxml.jackson.databind.JsonNode removeSimpleAttributeFromArray(com.fasterxml.jackson.databind.JsonNode jsonNode,
String value)
jsonNode - the array from which the value should be removedvalue - the value that should be removed from the documentpublic static com.fasterxml.jackson.databind.JsonNode addAttribute(com.fasterxml.jackson.databind.JsonNode jsonNode,
String attributeName,
com.fasterxml.jackson.databind.JsonNode newAttriute)
jsonNode - the json node from which the attribute should be removedattributeName - the name of the attribute to removenewAttriute - the new attribute that should be addedpublic static com.fasterxml.jackson.databind.JsonNode addAttributeToArray(com.fasterxml.jackson.databind.JsonNode jsonArray,
com.fasterxml.jackson.databind.JsonNode newAttriute)
jsonArray - the json node from which the attribute should be removednewAttriute - the new attribute that should be addedpublic static <T> com.fasterxml.jackson.databind.JsonNode writeValue(com.fasterxml.jackson.databind.JsonNode jsonNode,
String attributeName,
T value)
jsonNode - the json node from which the attribute should be removedattributeName - the name of the attribute to removevalue - the value of the new replaced nodepublic static com.fasterxml.jackson.databind.JsonNode replaceNode(com.fasterxml.jackson.databind.JsonNode jsonNode,
String attributeName,
com.fasterxml.jackson.databind.JsonNode replaceNode)
jsonNode - the json node from which the attribute should be removedattributeName - the name of the attribute to removereplaceNode - the new node that should be used as replacementpublic static <T extends com.fasterxml.jackson.databind.node.ObjectNode> T copyResourceToObject(com.fasterxml.jackson.databind.JsonNode resource,
Class<T> type)
resource - the resource that holds the content that must be moved to the new objecttype - the type from which an instance will be created with a noArgs constructorresource-nodepublic static Optional<com.fasterxml.jackson.databind.JsonNode> getSimpleAttributeByName(com.fasterxml.jackson.databind.JsonNode jsonNode, String attributeName)
attributeName - the scim name of the attribute e.g. "userName" of "name.givenName"public static boolean isValidJson(String json)
json - the string to validatepublic static String toJsonString(com.fasterxml.jackson.databind.JsonNode jsonNode)
public static String toPrettyJsonString(com.fasterxml.jackson.databind.JsonNode jsonNode)
public static boolean isEmpty(com.fasterxml.jackson.databind.JsonNode jsonNode)
Copyright © 2020. All rights reserved.