Package edu.iu.client

Class IuJson

java.lang.Object
edu.iu.client.IuJson

public class IuJson extends Object
JSON-P processing utilities.
  • Field Details

  • Method Details

    • parse

      public static JsonValue parse(HttpResponse<InputStream> serialized)
      Parses a JSON value from an HTTP response.
      Parameters:
      serialized - raw serialized JSON input stream
      Returns:
      JsonValue
    • parse

      public static JsonValue parse(InputStream serialized)
      Parses a JSON value from serialized form.
      Parameters:
      serialized - raw serialized JSON input stream
      Returns:
      JsonValue
    • parse

      public static JsonValue parse(String serialized)
      Parses a JSON value from serialized form.
      Parameters:
      serialized - raw serialized JSON data, as generated by JsonValue.toString()
      Returns:
      JsonValue
    • serialize

      public static void serialize(JsonValue value, OutputStream out)
      Serializes a JSON value to an OutputStream.
      Parameters:
      value - JsonValue
      out - OutputStream
    • wrap

      public static <T> T wrap(JsonObject value, Class<T> targetInterface)
      Wraps a JSON object in a java interface.
      Type Parameters:
      T - target interface type
      Parameters:
      value - value
      targetInterface - target interface class
      Returns:
      JsonProxy
    • wrap

      public static <T> T wrap(JsonObject value, Class<T> targetInterface, Function<Type,IuJsonAdapter<?>> valueAdapter)
      Wraps a JSON object in a java interface.
      Type Parameters:
      T - target interface type
      Parameters:
      value - value
      targetInterface - target interface class
      valueAdapter - transform function: receives a JsonValue and method return type, if custom handling returns an object other than the original value
      Returns:
      JsonProxy
    • unwrap

      public static JsonObject unwrap(Object jsonProxy)
      Retrieves the JsonObject from a JsonProxy wrapper.
      Parameters:
      jsonProxy - wrapper
      Returns:
      JsonObject
    • bool

      public static JsonValue bool(boolean value)
      Creates a JSON value from a boolean.
      Parameters:
      value - boolean
      Returns:
      JsonValue
    • number

      public static JsonNumber number(Number value)
      Creates a JSON value from a Number.
      Parameters:
      value - Number
      Returns:
      JsonNumber
    • string

      public static JsonString string(String value)
      Creates a JSON value from a String.
      Parameters:
      value - String
      Returns:
      JsonString
    • array

      public static JsonArrayBuilder array()
      Creates an array builder that rejects duplicate values.
      Returns:
      JsonArrayBuilder
    • array

      public static JsonArrayBuilder array(JsonArray array)
      Creates a builder for modifying an array.
      Parameters:
      array - array to copy
      Returns:
      JsonArrayBuilder
    • object

      public static JsonObjectBuilder object()
      Creates an object builder that rejects duplicate values.
      Returns:
      JsonObjectBuilder
    • object

      public static JsonObjectBuilder object(JsonObject object)
      Creates a builder for modifying an object.
      Parameters:
      object - object to copy
      Returns:
      JsonObjectBuilder
    • add

      public static void add(JsonObjectBuilder builder, String name, Object value)
      Adds a value to an object builder.
      Parameters:
      builder - JsonObjectBuilder
      name - name
      value - value
    • add

      public static <T> void add(JsonObjectBuilder builder, String name, Supplier<T> valueSupplier, IuJsonAdapter<T> adapter)
      Adds a value to an object builder.
      Type Parameters:
      T - value type
      Parameters:
      builder - JsonObjectBuilder
      name - property name
      valueSupplier - value supplier; if null is returned, the property will be undefined
      adapter - JSON type adapter for handling non-null values
    • add

      public static <T> void add(JsonObjectBuilder builder, String name, T value, BooleanSupplier condition)
      Adds a value to an object builder.
      Type Parameters:
      T - value type
      Parameters:
      builder - JsonObjectBuilder
      name - property name
      value - value
      condition - supplies true if the value should be added; false to do nothing
    • add

      public static <T> void add(JsonObjectBuilder builder, String name, Supplier<T> valueSupplier, BooleanSupplier condition, IuJsonAdapter<T> adapter)
      Adds a value to an object builder.
      Type Parameters:
      T - value type
      Parameters:
      builder - JsonObjectBuilder
      name - property name
      valueSupplier - value supplier
      condition - supplies true if the value should be added; false to do nothing
      adapter - JSON type adapter for handling non-null values
    • add

      public static <T> void add(JsonArrayBuilder builder, T value)
      Adds a value to an array builder.
      Type Parameters:
      T - value type
      Parameters:
      builder - JsonArrayBuilder
      value - value
    • add

      public static <T> void add(JsonArrayBuilder builder, Supplier<T> valueSupplier, IuJsonAdapter<T> adapter)
      Adds a value to an array builder.
      Type Parameters:
      T - value type
      Parameters:
      builder - JsonArrayBuilder
      valueSupplier - value supplier
      adapter - JSON type adapter for handling non-null values
    • add

      public static <T> void add(JsonArrayBuilder builder, T value, BooleanSupplier condition)
      Adds a value to an array builder.
      Type Parameters:
      T - value type
      Parameters:
      builder - JsonArrayBuilder
      value - value
      condition - supplies true if the value should be added; false to do nothing
    • add

      public static <T> void add(JsonArrayBuilder builder, Supplier<T> valueSupplier, BooleanSupplier condition, IuJsonAdapter<T> adapter)
      Adds a value to an array builder.
      Type Parameters:
      T - value type
      Parameters:
      builder - JsonArrayBuilder
      valueSupplier - value supplier
      condition - supplies true if the value should be added; false to do nothing
      adapter - JSON type adapter for handling non-null values
    • get

      public static <T> T get(JsonObject object, String name)
      Gets a property value from a JSON object.
      Type Parameters:
      T - result type
      Parameters:
      object - JsonObject
      name - property name
      Returns:
      property value
    • get

      public static <T> T get(JsonObject object, String name, IuJsonAdapter<T> adapter)
      Gets a property value from a JSON object.
      Type Parameters:
      T - result type
      Parameters:
      object - JsonObject
      name - property name
      adapter - adapter for converting non-null values
      Returns:
      property value
    • nonNull

      public static <T> T nonNull(JsonObject object, String name, IuJsonAdapter<T> adapter)
      Gets a non-null property value from a JSON object.
      Type Parameters:
      T - result type
      Parameters:
      object - JsonObject
      name - property name
      adapter - adapter for converting non-null values
      Returns:
      property value
      Throws:
      NullPointerException - if the property value is JsonValue.NULL
    • get

      public static <T> void get(JsonObject object, String name, Consumer<T> consumer)
      Gets a property value from a JSON object, accepting if non-null.
      Type Parameters:
      T - result type
      Parameters:
      object - JsonObject
      name - property name
      consumer - accepts the property value if non-null; else skipped
    • get

      public static <T> void get(JsonObject object, String name, IuJsonAdapter<T> adapter, Consumer<T> consumer)
      Gets a property value from a JSON object, accepting if non-null..
      Type Parameters:
      T - result type
      Parameters:
      object - JsonObject
      name - property name
      adapter - JSON type adapter
      consumer - accepts the property value if non-null; else skipped
    • get

      public static <T> T get(JsonObject object, String name, T defaultValue, IuJsonAdapter<T> adapter)
      Gets a property value from a JSON object.
      Type Parameters:
      T - result type
      Parameters:
      object - JsonObject
      name - property name
      defaultValue - value to return if the property is missing
      adapter - adapter for converting non-null values to Java
      Returns:
      property value, or defaultValue if the property is missing