Package com.github.dakusui.json
Class JsonUtils
java.lang.Object
com.github.dakusui.json.JsonUtils
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic doublestatic doubleasDoubleWithDefault(com.google.gson.JsonElement base, double defaultValue, Object... path) static floatstatic floatasFloatWithDefault(com.google.gson.JsonElement base, float defaultValue, Object... path) static intstatic intasIntWithDefault(com.google.gson.JsonElement base, int defaultValue, Object... path) static com.google.gson.JsonArrayasJsonArray(com.google.gson.JsonElement base, Object... path) static com.google.gson.JsonArrayasJsonArrayWithDefault(com.google.gson.JsonElement base, com.google.gson.JsonArray defaultValue, Object... path) static com.google.gson.JsonArrayasJsonArrayWithPromotion(com.google.gson.JsonElement base, Object... path) static com.google.gson.JsonElementasJsonElement(com.google.gson.JsonElement base, int from, Object[] path) static com.google.gson.JsonElementasJsonElement(com.google.gson.JsonElement base, Object... path) static com.google.gson.JsonElementasJsonElementWithDefault(com.google.gson.JsonElement base, com.google.gson.JsonElement defaultValue, int from, Object[] path) static com.google.gson.JsonElementasJsonElementWithDefault(com.google.gson.JsonElement base, com.google.gson.JsonElement defaultValue, Object... path) static com.google.gson.JsonObjectasJsonObject(com.google.gson.JsonObject base, Object... path) static com.google.gson.JsonObjectasJsonObjectWithDefault(com.google.gson.JsonObject base, com.google.gson.JsonObject defaultValue, Object... path) static com.google.gson.JsonObjectasJsonObjectWithPromotion(com.google.gson.JsonElement base, String[] prioritizedKeys, Object... path) static longstatic longasLongWithDefault(com.google.gson.JsonElement base, long defaultValue, Object... path) static Stringstatic StringasStringWithDefault(com.google.gson.JsonElement base, String defaultValue, Object... path) buildPathInfo(com.google.gson.JsonObject root) static com.google.gson.JsonObjectcreateSummaryJsonObjectFromPaths(com.google.gson.JsonObject rootJsonObject, List<Object>... paths) findPathOf(com.google.gson.JsonElement target, com.google.gson.JsonObject root) static StringfindPathStringOf(com.google.gson.JsonElement target, com.google.gson.JsonObject root) Returns a string representation of a path to a JSON elementtargetinrootJSON object node.static StringformatPath(Object... relPath) static booleankeyIterator(com.google.gson.JsonObject json) static com.google.gson.JsonObjectmerge(com.google.gson.JsonObject left, com.google.gson.JsonObject right) static com.google.gson.JsonObjectstatic StringsummarizeJsonElement(com.google.gson.JsonElement jsonElement) static com.google.gson.JsonElement
-
Constructor Details
-
JsonUtils
public JsonUtils()
-
-
Method Details
-
summarizeJsonElement
-
findPathStringOf
public static String findPathStringOf(com.google.gson.JsonElement target, com.google.gson.JsonObject root) Returns a string representation of a path to a JSON elementtargetinrootJSON object node.- Parameters:
target- A JSON element whose path inrootis searched for.root- A root JSON object node wheretarget's path is searched.- Returns:
- A string representation of path to
targetinroot.
-
findPathOf
-
createSummaryJsonObjectFromPaths
@SafeVarargs public static com.google.gson.JsonObject createSummaryJsonObjectFromPaths(com.google.gson.JsonObject rootJsonObject, List<Object>... paths) -
asJsonElementWithDefault
public static com.google.gson.JsonElement asJsonElementWithDefault(com.google.gson.JsonElement base, com.google.gson.JsonElement defaultValue, int from, Object[] path) throws JsonInvalidPathException - Throws:
JsonInvalidPathException
-
asJsonElement
public static com.google.gson.JsonElement asJsonElement(com.google.gson.JsonElement base, int from, Object[] path) throws JsonInvalidPathException - Throws:
JsonInvalidPathException
-
hasPath
-
asJsonObjectWithDefault
public static com.google.gson.JsonObject asJsonObjectWithDefault(com.google.gson.JsonObject base, com.google.gson.JsonObject defaultValue, Object... path) throws JsonTypeMismatchException, JsonInvalidPathException -
asJsonObject
public static com.google.gson.JsonObject asJsonObject(com.google.gson.JsonObject base, Object... path) throws JsonTypeMismatchException, JsonInvalidPathException -
asJsonObjectWithPromotion
public static com.google.gson.JsonObject asJsonObjectWithPromotion(com.google.gson.JsonElement base, String[] prioritizedKeys, Object... path) throws JsonInvalidPathException, JsonTypeMismatchException -
asJsonArrayWithPromotion
public static com.google.gson.JsonArray asJsonArrayWithPromotion(com.google.gson.JsonElement base, Object... path) throws JsonInvalidPathException, JsonTypeMismatchException -
asJsonArray
public static com.google.gson.JsonArray asJsonArray(com.google.gson.JsonElement base, Object... path) throws JsonException - Throws:
JsonException
-
asJsonArrayWithDefault
public static com.google.gson.JsonArray asJsonArrayWithDefault(com.google.gson.JsonElement base, com.google.gson.JsonArray defaultValue, Object... path) throws JsonTypeMismatchException, JsonInvalidPathException -
asJsonElementWithDefault
public static com.google.gson.JsonElement asJsonElementWithDefault(com.google.gson.JsonElement base, com.google.gson.JsonElement defaultValue, Object... path) throws JsonInvalidPathException - Throws:
JsonInvalidPathException
-
asJsonElement
public static com.google.gson.JsonElement asJsonElement(com.google.gson.JsonElement base, Object... path) throws JsonInvalidPathException - Throws:
JsonInvalidPathException
-
asString
public static String asString(com.google.gson.JsonElement base, Object... path) throws JsonTypeMismatchException, JsonInvalidPathException -
asStringWithDefault
public static String asStringWithDefault(com.google.gson.JsonElement base, String defaultValue, Object... path) throws JsonTypeMismatchException, JsonInvalidPathException -
asInt
public static int asInt(com.google.gson.JsonElement base, Object... path) throws JsonTypeMismatchException, JsonFormatException, JsonInvalidPathException -
asIntWithDefault
public static int asIntWithDefault(com.google.gson.JsonElement base, int defaultValue, Object... path) throws JsonTypeMismatchException, JsonFormatException, JsonInvalidPathException -
asLong
public static long asLong(com.google.gson.JsonElement base, Object... path) throws JsonTypeMismatchException, JsonFormatException, JsonInvalidPathException -
asLongWithDefault
public static long asLongWithDefault(com.google.gson.JsonElement base, long defaultValue, Object... path) throws JsonTypeMismatchException, JsonFormatException, JsonInvalidPathException -
asFloat
public static float asFloat(com.google.gson.JsonElement base, Object... path) throws JsonTypeMismatchException, JsonFormatException, JsonInvalidPathException -
asFloatWithDefault
public static float asFloatWithDefault(com.google.gson.JsonElement base, float defaultValue, Object... path) throws JsonTypeMismatchException, JsonFormatException, JsonInvalidPathException -
asDouble
public static double asDouble(com.google.gson.JsonElement base, Object... path) throws JsonException - Throws:
JsonException
-
asDoubleWithDefault
public static double asDoubleWithDefault(com.google.gson.JsonElement base, double defaultValue, Object... path) throws JsonTypeMismatchException, JsonFormatException, JsonInvalidPathException -
buildPathInfo
-
toJson
-
keyIterator
-
formatPath
-
merge
public static com.google.gson.JsonObject merge(com.google.gson.JsonObject left, com.google.gson.JsonObject right) throws JsonInvalidPathException - Throws:
JsonInvalidPathException
-
merge
public static com.google.gson.JsonObject merge(com.google.gson.JsonObject left, com.google.gson.JsonObject right, List<Object> relPath) throws JsonInvalidPathException - Throws:
JsonInvalidPathException
-