java.lang.Object
edu.iu.client.IuJson
JSON-P processing utilities.
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionstatic <T> void
add
(JsonArrayBuilder builder, Supplier<T> valueSupplier, IuJsonAdapter<T> adapter) Adds a value to an array builder.static <T> void
add
(JsonArrayBuilder builder, Supplier<T> valueSupplier, BooleanSupplier condition, IuJsonAdapter<T> adapter) Adds a value to an array builder.static <T> void
add
(JsonArrayBuilder builder, T value) Adds a value to an array builder.static <T> void
add
(JsonArrayBuilder builder, T value, BooleanSupplier condition) Adds a value to an array builder.static void
add
(JsonObjectBuilder builder, String name, Object value) Adds a value to an object builder.static <T> void
add
(JsonObjectBuilder builder, String name, Supplier<T> valueSupplier, IuJsonAdapter<T> adapter) Adds a value to an object builder.static <T> void
add
(JsonObjectBuilder builder, String name, Supplier<T> valueSupplier, BooleanSupplier condition, IuJsonAdapter<T> adapter) Adds a value to an object builder.static <T> void
add
(JsonObjectBuilder builder, String name, T value, BooleanSupplier condition) Adds a value to an object builder.static JsonArrayBuilder
array()
Creates an array builder that rejects duplicate values.static JsonArrayBuilder
Creates a builder for modifying an array.static JsonValue
bool
(boolean value) Creates a JSON value from aboolean
.static <T> T
get
(JsonObject object, String name) Gets a property value from a JSON object.static <T> T
get
(JsonObject object, String name, IuJsonAdapter<T> adapter) Gets a property value from a JSON object.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..static <T> void
get
(JsonObject object, String name, Consumer<T> consumer) Gets a property value from a JSON object, accepting if non-null.static <T> T
get
(JsonObject object, String name, T defaultValue, IuJsonAdapter<T> adapter) Gets a property value from a JSON object.static <T> T
nonNull
(JsonObject object, String name, IuJsonAdapter<T> adapter) Gets a non-null property value from a JSON object.static JsonNumber
Creates a JSON value from aNumber
.static JsonObjectBuilder
object()
Creates an object builder that rejects duplicate values.static JsonObjectBuilder
object
(JsonObject object) Creates a builder for modifying an object.static JsonValue
parse
(InputStream serialized) Parses a JSON value from serialized form.static JsonValue
Parses a JSON value from serialized form.static JsonValue
parse
(HttpResponse<InputStream> serialized) Parses a JSON value from an HTTP response.static void
serialize
(JsonValue value, OutputStream out) Serializes a JSON value to anOutputStream
.static JsonString
Creates a JSON value from aString
.static JsonObject
Retrieves theJsonObject
from aJsonProxy
wrapper.static <T> T
wrap
(JsonObject value, Class<T> targetInterface) Wraps a JSON object in a java interface.static <T> T
wrap
(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
-JsonValue
out
-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 theJsonObject
from aJsonProxy
wrapper.- 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
-JsonObjectBuilder
name
- 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
-JsonObjectBuilder
name
- 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
-JsonObjectBuilder
name
- 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
-JsonObjectBuilder
name
- 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
-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 supplieradapter
- JSON type adapter for handling non-null values
-
add
Adds a value to an array builder.- Type Parameters:
T
- value type- Parameters:
builder
-JsonArrayBuilder
value
- 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
-JsonArrayBuilder
valueSupplier
- 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
-JsonObject
name
- property name- Returns:
- property value
-
get
Gets a property value from a JSON object.- Type Parameters:
T
- result type- Parameters:
object
-JsonObject
name
- 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
-JsonObject
name
- 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
-JsonObject
name
- 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
-JsonObject
name
- 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
-JsonObject
name
- 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
-