Package ai.devtools.utils
Class JsonUtils
- java.lang.Object
-
- ai.devtools.utils.JsonUtils
-
public class JsonUtils extends Object
Shared utility methods for common tasks
-
-
Constructor Summary
Constructors Constructor Description JsonUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static booleanbooleanFromJson(com.google.gson.JsonObject jo, String key)Convenience method, extract a boolean value associated with the specified key on a JsonObject.static doubledoubleFromJson(com.google.gson.JsonObject jo, String key)Convenience method, extract a double value associated with the specified key on a JsonObject.static intintFromJson(com.google.gson.JsonObject jo, String key)Convenience method, extract an int value associated with the specified key on a JsonObject.static com.google.gson.JsonObjectresponseAsJson(okhttp3.Response r)Convenience method, extract the body of aResponseas aJsonObject.static StringstringFromJson(com.google.gson.JsonObject jo, String key)Convenience method, extract a String value associated with the specified key on a JsonObject.
-
-
-
Method Detail
-
responseAsJson
public static com.google.gson.JsonObject responseAsJson(okhttp3.Response r)
Convenience method, extract the body of aResponseas aJsonObject.- Parameters:
r- The Response object to use- Returns:
- The body of
ras aJsonObject.
-
stringFromJson
public static String stringFromJson(com.google.gson.JsonObject jo, String key)
Convenience method, extract a String value associated with the specified key on a JsonObject.- Parameters:
jo- The JsonObject to extract a String fromkey- The key associated with the value to extract- Returns:
- The value associated with
key, or the empty String ifkeywas not injo.
-
doubleFromJson
public static double doubleFromJson(com.google.gson.JsonObject jo, String key)Convenience method, extract a double value associated with the specified key on a JsonObject.- Parameters:
jo- The JsonObject to extract a double fromkey- The key associated with the value to extract- Returns:
- The value associated with
key, or 0.0 ifkeywas not injo.
-
intFromJson
public static int intFromJson(com.google.gson.JsonObject jo, String key)Convenience method, extract an int value associated with the specified key on a JsonObject.- Parameters:
jo- The JsonObject to extract an int fromkey- The key associated with the value to extract- Returns:
- The value associated with
key, or 0 ifkeywas not injo.
-
booleanFromJson
public static boolean booleanFromJson(com.google.gson.JsonObject jo, String key)Convenience method, extract a boolean value associated with the specified key on a JsonObject.- Parameters:
jo- The JsonObject to extract a boolean fromkey- The key associated with the value to extract- Returns:
- The value associated with
key, or false ifkeywas not injo.
-
-