Class JsonHelper
java.lang.Object
de.captaingoldfish.scim.sdk.common.utils.JsonHelper
author Pascal Knueppel
created at: 28.09.2019 - 00:05
created at: 28.09.2019 - 00:05
-
Method Summary
Modifier and TypeMethodDescriptionstatic com.fasterxml.jackson.databind.JsonNodeaddAttribute(com.fasterxml.jackson.databind.JsonNode jsonNode, String attributeName, com.fasterxml.jackson.databind.JsonNode newAttriute) will remove an attribute from the given jsonNodestatic com.fasterxml.jackson.databind.JsonNodeaddAttributeToArray(com.fasterxml.jackson.databind.JsonNode jsonArray, com.fasterxml.jackson.databind.JsonNode newAttriute) will remove an attribute from the given jsonNodestatic <T extends com.fasterxml.jackson.databind.JsonNode>
booleancontainsEqualObject(List<T> originalNodes, T jsonNode) jackson is currently not supporting comparison of int and long-nodes even if the nodes do have the same values. for this reason we are overriding the comparison here in case for number nodesstatic <T extends com.fasterxml.jackson.databind.node.ObjectNode>
TcopyResourceToObject(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 nodestatic 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 nodestatic <T extends ScimObjectNode>
TgetNewInstance(Class<T> type) builds a new instance of the given resource node typestatic 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 nodegetSimpleAttribute(com.fasterxml.jackson.databind.JsonNode jsonNode, String name) will get a string attribute with the given name from the given json nodestatic <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 nodegetSimpleAttributeArray(com.fasterxml.jackson.databind.JsonNode jsonNode, String attributeName) extracts a list of simple attributes from the given json nodegetSimpleAttributeArray(com.fasterxml.jackson.databind.JsonNode jsonNode, String attributeName, Class<T> type) extracts a list of simple attributes from the given json nodestatic 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 booleanisEmpty(com.fasterxml.jackson.databind.JsonNode jsonNode) override method for usage with wildfly 18 that still uses jackson 2.9.xstatic booleanisEqual(com.fasterxml.jackson.databind.JsonNode node1, com.fasterxml.jackson.databind.JsonNode node2) jackson is currently not supporting comparison of int and long-nodes even if the nodes do have the same values. for this reason we are overriding the comparison here in case for number nodesstatic booleanisValidJson(String json) validates if the given string structure is valid json or notstatic com.fasterxml.jackson.databind.JsonNodeloadJsonDocument(File file) will read a json document from a filestatic <T extends com.fasterxml.jackson.databind.node.ObjectNode>
TloadJsonDocument(File file, Class<T> type) will read a json document from a filestatic com.fasterxml.jackson.databind.JsonNodeloadJsonDocument(String classPathLocation) will read a json document from the classpathstatic <T extends com.fasterxml.jackson.databind.node.ObjectNode>
TloadJsonDocument(String classPathLocation, Class<T> type) will read a json document from the classpathstatic com.fasterxml.jackson.databind.JsonNodereadJsonDocument(String jsonDocument) will read a json document from the given stringstatic <T extends com.fasterxml.jackson.databind.node.ObjectNode>
TreadJsonDocument(String jsonDocument, Class<T> type) will read a json document from the given stringstatic com.fasterxml.jackson.databind.JsonNoderemoveAttribute(com.fasterxml.jackson.databind.JsonNode jsonNode, String attributeName) will remove an attribute from the given jsonNodestatic com.fasterxml.jackson.databind.JsonNoderemoveSimpleAttributeFromArray(com.fasterxml.jackson.databind.JsonNode jsonNode, String value) will remove a simple value from a simple array node in the given json documentstatic com.fasterxml.jackson.databind.JsonNodereplaceNode(com.fasterxml.jackson.databind.JsonNode jsonNode, String attributeName, com.fasterxml.jackson.databind.JsonNode replaceNode) will remove an attribute from the given jsonNodestatic StringtoJsonString(com.fasterxml.jackson.databind.JsonNode jsonNode) override method for usage with wildfly 18 that still uses jackson 2.9.xstatic StringtoPrettyJsonString(com.fasterxml.jackson.databind.JsonNode jsonNode) override method for usage with wildfly 18 that still uses jackson 2.9.xstatic <T> com.fasterxml.jackson.databind.JsonNodewriteValue(com.fasterxml.jackson.databind.JsonNode jsonNode, String attributeName, T value) will remove an attribute from the given jsonNode
-
Method Details
-
loadJsonDocument
will read a json document from the classpath- Parameters:
classPathLocation- the location of the document- Returns:
- the parsed json document
-
loadJsonDocument
public static <T extends com.fasterxml.jackson.databind.node.ObjectNode> T loadJsonDocument(String classPathLocation, Class<T> type) will read a json document from the classpath- Parameters:
classPathLocation- the location of the document- Returns:
- the parsed json document
-
loadJsonDocument
public static <T extends com.fasterxml.jackson.databind.node.ObjectNode> T loadJsonDocument(File file, Class<T> type) will read a json document from a file- Parameters:
file- the location of the document- Returns:
- the parsed json document
-
loadJsonDocument
will read a json document from a file- Parameters:
file- the location of the document- Returns:
- the parsed json document
-
readJsonDocument
will read a json document from the given string- Parameters:
jsonDocument- the direct json representation- Returns:
- the parsed json document
-
readJsonDocument
public static <T extends com.fasterxml.jackson.databind.node.ObjectNode> T readJsonDocument(String jsonDocument, Class<T> type) will read a json document from the given string- Parameters:
jsonDocument- the direct json representation- Returns:
- the parsed json document
-
getArrayAttribute
public 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- Parameters:
jsonNode- the json node from which the array should be extractedname- the name of the json array attribute- Returns:
- the json array attribute or an empty if the attribute is not present
-
getObjectAttribute
public 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- Parameters:
jsonNode- the json node from which the json object should be extractedname- the name of the json object attribute- Returns:
- the json object attribute or an empty if the attribute is not present
-
getSimpleAttributeArray
public static Optional<List<String>> getSimpleAttributeArray(com.fasterxml.jackson.databind.JsonNode jsonNode, String attributeName) extracts a list of simple attributes from the given json node- Parameters:
jsonNode- the json document containing an array with simple attributesattributeName- the name of the attribute that is an array with simple attributes- Returns:
- a list of attributes or an empty
-
getSimpleAttributeArray
public 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- Parameters:
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 array- Returns:
- a list of attributes or an empty
-
getSimpleAttribute
public 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- Parameters:
jsonNode- the json node to get the attribute fromname- the name of the attribute- Returns:
- the value as string or an empty
-
getSimpleAttribute
public 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- Parameters:
jsonNode- the json node to get the attribute fromname- the name of the attributetype- the type of the attribute to return- Returns:
- the value of the given type or an empty
-
removeAttribute
public static com.fasterxml.jackson.databind.JsonNode removeAttribute(com.fasterxml.jackson.databind.JsonNode jsonNode, String attributeName) will remove an attribute from the given jsonNode- Parameters:
jsonNode- the json node from which the attribute should be removedattributeName- the name of the attribute to remove
-
removeSimpleAttributeFromArray
public 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- Parameters:
jsonNode- the array from which the value should be removedvalue- the value that should be removed from the document
-
addAttribute
public 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- Parameters:
jsonNode- the json node from which the attribute should be removedattributeName- the name of the attribute to removenewAttriute- the new attribute that should be added
-
addAttributeToArray
public 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- Parameters:
jsonArray- the json node from which the attribute should be removednewAttriute- the new attribute that should be added
-
writeValue
public 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- Parameters:
jsonNode- the json node from which the attribute should be removedattributeName- the name of the attribute to removevalue- the value of the new replaced node
-
replaceNode
public 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- Parameters:
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 replacement
-
copyResourceToObject
public static <T extends com.fasterxml.jackson.databind.node.ObjectNode> T 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- Parameters:
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 constructor- Returns:
- a newly created instance with the content of the
resource-node
-
getNewInstance
builds a new instance of the given resource node type- Type Parameters:
T- the type must define a noArgs constructor- Parameters:
type- the type for which the instance should be build- Returns:
- the newly created instance
-
getSimpleAttributeByName
public 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.- Parameters:
attributeName- the scim name of the attribute e.g. "userName" of "name.givenName"- Returns:
- the json node or an empty
-
isValidJson
validates if the given string structure is valid json or not- Parameters:
json- the string to validate- Returns:
- true if the given string is a valid json structure, false else
-
toJsonString
override method for usage with wildfly 18 that still uses jackson 2.9.x -
toPrettyJsonString
override method for usage with wildfly 18 that still uses jackson 2.9.x -
isEmpty
public static boolean isEmpty(com.fasterxml.jackson.databind.JsonNode jsonNode) override method for usage with wildfly 18 that still uses jackson 2.9.x -
containsEqualObject
public static <T extends com.fasterxml.jackson.databind.JsonNode> boolean containsEqualObject(List<T> originalNodes, T jsonNode) jackson is currently not supporting comparison of int and long-nodes even if the nodes do have the same values. for this reason we are overriding the comparison here in case for number nodes- Returns:
- true if the list contains a node that is equal to given complexNode, false else
-
isEqual
public static boolean isEqual(com.fasterxml.jackson.databind.JsonNode node1, com.fasterxml.jackson.databind.JsonNode node2) jackson is currently not supporting comparison of int and long-nodes even if the nodes do have the same values. for this reason we are overriding the comparison here in case for number nodes- Returns:
- true if the list contains a node that is equal to given complexNode, false else
-