public class JSONUtil
extends java.lang.Object
| Modifier and Type | Field and Description |
|---|---|
static com.fasterxml.jackson.databind.ObjectMapper |
MAPPER
A Jackson Databind
ObjectMapper singleton |
| Constructor and Description |
|---|
JSONUtil() |
| Modifier and Type | Method and Description |
|---|---|
static com.fasterxml.jackson.databind.JsonNode |
asJson(java.lang.Object value)
Convert object to
JsonNode |
static java.util.List<java.lang.String> |
asListOfString(com.fasterxml.jackson.databind.JsonNode arrayOrString)
This method takes a JsonNode representing an array, or a string, and converts it into a List of String items.
|
static java.util.List<java.lang.String> |
asListOfString(com.fasterxml.jackson.databind.JsonNode arrayOrString,
java.lang.String delimiter)
This method takes a JsonNode representing an array, or a string, and converts it into a List of String items.
|
static java.lang.String |
getClaimFromJWT(com.fasterxml.jackson.databind.JsonNode node,
java.lang.String... path)
Get specific claim from token.
|
static java.lang.String |
getClaimFromJWT(java.lang.String claim,
java.lang.Object token)
Get specific claim from token.
|
static com.fasterxml.jackson.databind.node.ObjectNode |
newObjectNode()
Create a new ObjectNode
|
static <T> T |
readJSON(java.io.InputStream is,
java.lang.Class<T> clazz)
Parse JSON from
InputStream into a specified type |
static <T> T |
readJSON(java.lang.String jsonString,
java.lang.Class<T> clazz)
Parse JSON from String into a specified type
|
public static final com.fasterxml.jackson.databind.ObjectMapper MAPPER
ObjectMapper singletonpublic static com.fasterxml.jackson.databind.node.ObjectNode newObjectNode()
public static <T> T readJSON(java.io.InputStream is,
java.lang.Class<T> clazz)
throws java.io.IOException
InputStream into a specified typeT - Generic type representing a return typeis - An InputStream to read JSON fromclazz - A class representing the type to return (e.g. JsonNode, ObjectNode, ArrayNode, String)java.io.IOException - If an error occurs while reading or parsing the inputpublic static <T> T readJSON(java.lang.String jsonString,
java.lang.Class<T> clazz)
throws java.io.IOException
T - Generic type representing a return typejsonString - JSON as a Stringclazz - A class representing the type to return (e.g. JsonNode, ObjectNode, ArrayNode, String)java.io.IOException - If an error occurs while reading or parsing the inputpublic static com.fasterxml.jackson.databind.JsonNode asJson(java.lang.Object value)
JsonNodevalue - Json-serializable objectpublic static java.lang.String getClaimFromJWT(java.lang.String claim,
java.lang.Object token)
claim - jq style query where nested names are specified using '.' as separatortoken - parsed objectpublic static java.lang.String getClaimFromJWT(com.fasterxml.jackson.databind.JsonNode node,
java.lang.String... path)
node - parsed JWT token payloadpath - name segments where all but last should each point to the next nested objectpublic static java.util.List<java.lang.String> asListOfString(com.fasterxml.jackson.databind.JsonNode arrayOrString)
If the passed node is a TextNode, the text is parsed into a list of items by using ' ' (space) as a delimiter. The resulting list can contain empty strings if two delimiters are present next to one another.
If the JsonNode is neither an ArrayNode, nor a TextNode an IllegalArgumentException is thrown.
arrayOrString - A JsonNode to convert into a list of Stringpublic static java.util.List<java.lang.String> asListOfString(com.fasterxml.jackson.databind.JsonNode arrayOrString,
java.lang.String delimiter)
The delimiter parameter is only used if the passed node is a TextNode. It is used to parse the node content
as a list of strings. The resulting list can contain empty strings if two delimiters are present next to one another.
If the JsonNode is neither an ArrayNode, nor a TextNode an IllegalArgumentException is thrown.
arrayOrString - A JsonNode to convert into a list of Stringdelimiter - A delimiter to use for parsing the TextNodeCopyright © 2023. All rights reserved.