Package ai.devtools.utils
Class JsonUtils
java.lang.Object
ai.devtools.utils.JsonUtils
Shared utility methods for common tasks
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic 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.
-
Constructor Details
-
JsonUtils
public JsonUtils()
-
-
Method Details
-
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
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
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
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
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.
-