public class JoltUtils extends Object
| Constructor and Description |
|---|
JoltUtils() |
| Modifier and Type | Method and Description |
|---|---|
static <T> T |
cast(Object object)
Type casts an input object to class indicated by TypeToken
|
static <E> E[] |
cast(Object[] object)
Type cast to array E[]
|
static Object |
compactJson(Object source)
Given a 'fluffy' json document, it recursively removes all null elements
to compact the json document
Warning: mutates the doc, destroys array order
|
static boolean |
isBlankJson(Object obj)
Given a json document checks if its jst blank doc, i.e.
|
static boolean |
isVacantJson(Object obj)
Vacant implies there are empty placeholders, i.e.
|
static List<Object[]> |
listKeyChains(Object source)
Given a json document, finds out absolute path to every leaf element
i.e.
|
static List<Object[]> |
listKeyChains(Object key,
Object value)
Helper/overridden method for listKeyChain(source), it accepts a key-value pair for convenience
note: "key": value (an item in map) and [value] (an item in list) is generalized here
as [value] is interpreted in json path as 1: value
|
static <T> T |
navigate(Object source,
Object... paths)
Navigate a JSON tree (made up of Maps and Lists) to "lookup" the value
at a particular path.
|
static <T> T |
navigateOrDefault(T defaultValue,
Object source,
Object... paths)
Navigate a JSON tree (made up of Maps and Lists) to "lookup" the value
at a particular path, but will return the supplied default value if
there are any problems.
|
static <T> T |
navigateSafe(T defaultValue,
Object source,
Object... paths)
Deprecated.
|
static <T> T |
navigateStrict(Object source,
Object... paths)
Navigate a JSON tree (made up of Maps and Lists) to "lookup" the value
at a particular path.
|
static <T> T |
remove(Object source,
Object... paths)
For a given non-null (json) object, removes and returns the value in the nested path provided
Warning: changes array order, to maintain order, use store(source, null, path ...) instead
|
static void |
removeRecursive(Object json,
String keyToRemove)
Removes a key recursively from anywhere in a JSON document.
|
static <T> T |
store(Object source,
T value,
Object... paths)
For a given non-null (json) object, save the valve in the nested path provided
|
static String |
toSimpleTraversrPath(Object[] paths)
Converts a standard json path to human readable SimpleTraversr compatible path
|
public static void removeRecursive(Object json, String keyToRemove)
json - the Jackson Object version of the JSON document
(contents changed by this call)keyToRemove - the key to remove from the documentpublic static <T> T navigate(Object source, Object... paths)
source - the source JSON object (Map, List, String, Number)paths - varargs path you want to travelpublic static <T> T navigateStrict(Object source, Object... paths) throws UnsupportedOperationException
source - the source JSON object (Map, List, String, Number)paths - varargs path you want to travelUnsupportedOperationException - if there was any problem walking the JSON tree structurepublic static <T> T navigateOrDefault(T defaultValue,
Object source,
Object... paths)
source - the source JSON object (Map, List, String, Number)paths - varargs path you want to travel@Deprecated public static <T> T navigateSafe(T defaultValue, Object source, Object... paths)
public static boolean isVacantJson(Object obj)
obj - sourcepublic static boolean isBlankJson(Object obj)
obj - sourcepublic static List<Object[]> listKeyChains(Object source)
source - jsonpublic static List<Object[]> listKeyChains(Object key, Object value)
key - value - public static String toSimpleTraversrPath(Object[] paths)
paths - the path array of objectspublic static <T> T cast(Object object)
object - the input object to castpublic static <E> E[] cast(Object[] object)
object - the input object to castpublic static Object compactJson(Object source)
source - public static <T> T store(Object source, T value, Object... paths)
source - the source json objectvalue - the value to storepaths - var args Object path to navigate down and store the object inpublic static <T> T remove(Object source, Object... paths)
source - the source json objectpaths - var args Object path to navigate down and removeCopyright © 2023. All rights reserved.