java.lang.Object
edu.iu.client.IuJson
JSON-P processing utilities.
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionstatic <T> voidadd(JsonArrayBuilder builder, Supplier<T> valueSupplier, IuJsonAdapter<T> adapter) Adds a value to an array builder.static <T> voidadd(JsonArrayBuilder builder, Supplier<T> valueSupplier, BooleanSupplier condition, IuJsonAdapter<T> adapter) Adds a value to an array builder.static <T> voidadd(JsonArrayBuilder builder, T value) Adds a value to an array builder.static <T> voidadd(JsonArrayBuilder builder, T value, BooleanSupplier condition) Adds a value to an array builder.static voidadd(JsonObjectBuilder builder, String name, Object value) Adds a value to an object builder.static <T> voidadd(JsonObjectBuilder builder, String name, Supplier<T> valueSupplier, IuJsonAdapter<T> adapter) Adds a value to an object builder.static <T> voidadd(JsonObjectBuilder builder, String name, Supplier<T> valueSupplier, BooleanSupplier condition, IuJsonAdapter<T> adapter) Adds a value to an object builder.static <T> voidadd(JsonObjectBuilder builder, String name, T value, BooleanSupplier condition) Adds a value to an object builder.static JsonArrayBuilderarray()Creates an array builder that rejects duplicate values.static JsonArrayBuilderCreates a builder for modifying an array.static JsonValuebool(boolean value) Creates a JSON value from aboolean.static <T> Tget(JsonObject object, String name) Gets a property value from a JSON object.static <T> Tget(JsonObject object, String name, IuJsonAdapter<T> adapter) Gets a property value from a JSON object.static <T> voidget(JsonObject object, String name, IuJsonAdapter<T> adapter, Consumer<T> consumer) Gets a property value from a JSON object, accepting if non-null..static <T> voidget(JsonObject object, String name, Consumer<T> consumer) Gets a property value from a JSON object, accepting if non-null.static <T> Tget(JsonObject object, String name, T defaultValue, IuJsonAdapter<T> adapter) Gets a property value from a JSON object.static <T> TnonNull(JsonObject object, String name, IuJsonAdapter<T> adapter) Gets a non-null property value from a JSON object.static JsonNumberCreates a JSON value from aNumber.static JsonObjectBuilderobject()Creates an object builder that rejects duplicate values.static JsonObjectBuilderobject(JsonObject object) Creates a builder for modifying an object.static JsonValueparse(InputStream serialized) Parses a JSON value from serialized form.static JsonValueParses a JSON value from serialized form.static JsonValueparse(HttpResponse<InputStream> serialized) Parses a JSON value from an HTTP response.static voidserialize(JsonValue value, OutputStream out) Serializes a JSON value to anOutputStream.static JsonStringCreates a JSON value from aString.static JsonObjectRetrieves theJsonObjectfrom aJsonProxywrapper.static <T> Twrap(JsonObject value, Class<T> targetInterface) Wraps a JSON object in a java interface.static <T> Twrap(JsonObject value, Class<T> targetInterface, Function<Type, IuJsonAdapter<?>> valueAdapter) Wraps a JSON object in a java interface.
-
Field Details
-
PROVIDER
SingletonJsonProvider.
-
-
Method Details
-
parse
Parses a JSON value from an HTTP response.- Parameters:
serialized- raw serialized JSON input stream- Returns:
JsonValue
-
parse
Parses a JSON value from serialized form.- Parameters:
serialized- raw serialized JSON input stream- Returns:
JsonValue
-
parse
Parses a JSON value from serialized form.- Parameters:
serialized- raw serialized JSON data, as generated byJsonValue.toString()- Returns:
JsonValue
-
serialize
Serializes a JSON value to anOutputStream.- Parameters:
value-JsonValueout-OutputStream
-
wrap
Wraps a JSON object in a java interface.- Type Parameters:
T- target interface type- Parameters:
value- valuetargetInterface- 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. -
unwrap
Retrieves theJsonObjectfrom aJsonProxywrapper.- Parameters:
jsonProxy- wrapper- Returns:
JsonObject
-
bool
Creates a JSON value from aboolean. -
number
Creates a JSON value from aNumber.- Parameters:
value-Number- Returns:
JsonNumber
-
string
Creates a JSON value from aString.- Parameters:
value-String- Returns:
JsonString
-
array
Creates an array builder that rejects duplicate values.- Returns:
JsonArrayBuilder
-
array
Creates a builder for modifying an array.- Parameters:
array- array to copy- Returns:
JsonArrayBuilder
-
object
Creates an object builder that rejects duplicate values.- Returns:
JsonObjectBuilder
-
object
Creates a builder for modifying an object.- Parameters:
object- object to copy- Returns:
JsonObjectBuilder
-
add
Adds a value to an object builder.- Parameters:
builder-JsonObjectBuildername- namevalue- 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-JsonObjectBuildername- property namevalueSupplier- value supplier; if null is returned, the property will be undefinedadapter- 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-JsonObjectBuildername- property namevalue- valuecondition- 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-JsonObjectBuildername- property namevalueSupplier- value suppliercondition- supplies true if the value should be added; false to do nothingadapter- JSON type adapter for handling non-null values
-
add
Adds a value to an array builder.- Type Parameters:
T- value type- Parameters:
builder-JsonArrayBuildervalue- 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-JsonArrayBuildervalueSupplier- value supplieradapter- JSON type adapter for handling non-null values
-
add
Adds a value to an array builder.- Type Parameters:
T- value type- Parameters:
builder-JsonArrayBuildervalue- valuecondition- 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-JsonArrayBuildervalueSupplier- value suppliercondition- supplies true if the value should be added; false to do nothingadapter- JSON type adapter for handling non-null values
-
get
Gets a property value from a JSON object.- Type Parameters:
T- result type- Parameters:
object-JsonObjectname- property name- Returns:
- property value
-
get
Gets a property value from a JSON object.- Type Parameters:
T- result type- Parameters:
object-JsonObjectname- property nameadapter- adapter for converting non-null values- Returns:
- property value
-
nonNull
Gets a non-null property value from a JSON object.- Type Parameters:
T- result type- Parameters:
object-JsonObjectname- property nameadapter- adapter for converting non-null values- Returns:
- property value
- Throws:
NullPointerException- if the property value isJsonValue.NULL
-
get
Gets a property value from a JSON object, accepting if non-null.- Type Parameters:
T- result type- Parameters:
object-JsonObjectname- property nameconsumer- 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-JsonObjectname- property nameadapter- JSON type adapterconsumer- accepts the property value if non-null; else skipped
-
get
Gets a property value from a JSON object.- Type Parameters:
T- result type- Parameters:
object-JsonObjectname- property namedefaultValue- value to return if the property is missingadapter- adapter for converting non-null values to Java- Returns:
- property value, or defaultValue if the property is missing
-