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 |
isEmptyJson(Object obj)
Deprecated.
|
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 inside a json object in quick and dirty way.
|
static <T> T |
navigateSafe(T defaultValue,
Object source,
Object... paths)
Navigate inside a json object in quick and "dirtier" way, i.e.
|
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 objectpaths - the paths array to travelNullPointerException - if the source is nullUnsupportedOperationException - if the source is not Map or Listpublic static <T> T navigateSafe(T defaultValue,
Object source,
Object... paths)
source - the sourcepaths - the paths arrayUnsupportedOperationException - the unsupported operation exception@Deprecated public static boolean isEmptyJson(Object obj)
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 © 2016. All rights reserved.