Class JsonUtil

java.lang.Object
tripleplay.util.JsonUtil

public class JsonUtil extends Object
Facilities for parsing JSON data
  • Constructor Details

    • JsonUtil

      public JsonUtil()
  • Method Details

    • getEnum

      public static <T extends Enum<T>> T getEnum(Json.Object json, String key, Class<T> enumType, T defaultVal)
      Returns:
      the Enum whose name corresponds to string for the given key, or defaultVal if the key doesn't exist.
    • requireEnum

      public static <T extends Enum<T>> T requireEnum(Json.Object json, String key, Class<T> enumType)
      Returns:
      the Enum whose name corresponds to string for the given key. Throws a RuntimeException if the key doesn't exist.
    • getBoolean

      public static boolean getBoolean(Json.Object json, String key, boolean defaultVal)
      Returns:
      the boolean value at the given key, or defaultVal if the key doesn't exist.
    • requireBoolean

      public static boolean requireBoolean(Json.Object json, String key)
      Returns:
      the boolean value at the given key.
      Throws:
      RuntimeException - if the key doesn't exist.
    • getNumber

      public static double getNumber(Json.Object json, String key, double defaultVal)
      Returns:
      the double value at the given key, or defaultVal if the key doesn't exist.
    • requireNumber

      public static double requireNumber(Json.Object json, String key)
      Returns:
      the double value at the given key.
      Throws:
      RuntimeException - if the key doesn't exist.
    • getFloat

      public static float getFloat(Json.Object json, String key, float defaultVal)
      Returns:
      the float value at the given key, or defaultVal if the key doesn't exist.
    • requireFloat

      public static float requireFloat(Json.Object json, String key)
      Returns:
      the float value at the given key.
      Throws:
      RuntimeException - if the key doesn't exist.
    • getInt

      public static int getInt(Json.Object json, String key, int defaultVal)
      Returns:
      the int value at the given key, or defaultVal if the key doesn't exist.
    • requireInt

      public static int requireInt(Json.Object json, String key)
      Returns:
      the int value at the given key.
      Throws:
      RuntimeException - if the key doesn't exist.
    • getString

      public static String getString(Json.Object json, String key, String defaultVal)
      Returns:
      the String value at the given key, or defaultVal if the key doesn't exist.
    • requireString

      public static String requireString(Json.Object json, String key)
      Returns:
      the String value at the given key.
      Throws:
      RuntimeException - if the key doesn't exist.
    • getObject

      public static Json.Object getObject(Json.Object json, String key, Json.Object defaultVal)
      Returns:
      the Json.Object value at the given key, or defaultVal if the key doesn't exist.
    • requireObject

      public static Json.Object requireObject(Json.Object json, String key)
      Returns:
      the Json.Object at the given key.
      Throws:
      RuntimeException - if the key doesn't exist.
    • getArray

      public static Json.Array getArray(Json.Object json, String key, Json.Array defaultVal)
      Returns:
      the Json.Object value at the given key, or defaultVal if the key doesn't exist.
    • requireArray

      public static Json.Array requireArray(Json.Object json, String key)
      Returns:
      the Json.Array at the given key.
      Throws:
      RuntimeException - if the key doesn't exist.
    • toString

      public static String toString(Platform plat, Json.Object json, boolean verbose)
      Returns:
      a String representation of the given Json