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
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static boolean
    booleanFromJson(com.google.gson.JsonObject jo, String key)
    Convenience method, extract a boolean value associated with the specified key on a JsonObject.
    static double
    doubleFromJson(com.google.gson.JsonObject jo, String key)
    Convenience method, extract a double value associated with the specified key on a JsonObject.
    static int
    intFromJson(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.JsonObject
    responseAsJson(okhttp3.Response r)
    Convenience method, extract the body of a Response as a JsonObject.
    static String
    stringFromJson(com.google.gson.JsonObject jo, String key)
    Convenience method, extract a String value associated with the specified key on a JsonObject.

    Methods inherited from class java.lang.Object

    equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • JsonUtils

      public JsonUtils()
  • Method Details

    • responseAsJson

      public static com.google.gson.JsonObject responseAsJson(okhttp3.Response r)
      Convenience method, extract the body of a Response as a JsonObject.
      Parameters:
      r - The Response object to use
      Returns:
      The body of r as a JsonObject.
    • 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 from
      key - The key associated with the value to extract
      Returns:
      The value associated with key, or the empty String if key was not in jo.
    • 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 from
      key - The key associated with the value to extract
      Returns:
      The value associated with key, or 0.0 if key was not in jo.
    • 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 from
      key - The key associated with the value to extract
      Returns:
      The value associated with key, or 0 if key was not in jo.
    • 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 from
      key - The key associated with the value to extract
      Returns:
      The value associated with key, or false if key was not in jo.