public final class JavaxJson extends Object
ProgressCheckFactory configs using only three-letter identifiers.
Recommend using import static net.adamcin.oakpal.core.JavaxJson.*;
| Modifier and Type | Class and Description |
|---|---|
static class |
JavaxJson.Arr
Constructs an array by iterating over a list of
JavaxJson.Value instances. |
static interface |
JavaxJson.As<TYPE>
Defines a get method returns the constructed type parameter.
|
static interface |
JavaxJson.Cursor
Type which allows a different fluent style for building keys, i.e.
|
static interface |
JavaxJson.HasValue
Defines a method toValue which coalesces the underlying value to prevent over-wrapping by the
val(Object) method. |
static class |
JavaxJson.Key
Iterative key-value pair type for building
JavaxJson.Obj instances. |
static class |
JavaxJson.KeyCursor
Cursor type originating from a call to
key(String), and which therefore returns a lone
JavaxJson.Key for JavaxJson.KeyCursor.val(Object). |
static class |
JavaxJson.Obj
Constructs an object by iterating over a list of
JavaxJson.Key instances. |
static class |
JavaxJson.ObjCursor
Cursor type originating from a call to
JavaxJson.Key.key(String) or JavaxJson.Obj.key(String), and which therefore
returns a new JavaxJson.Obj with the newly-finished key appended internally. |
static class |
JavaxJson.Value
Discrete value wrapper.
|
| Modifier and Type | Field and Description |
|---|---|
static Function<javax.json.JsonValue,String> |
JSON_VALUE_STRING
This is needed to easily map untyped
JsonString instances to String, since we don't use
the JsonObject.getString(String) methods. |
| Modifier and Type | Method and Description |
|---|---|
static JavaxJson.Arr |
arr(Object... values)
Creates an array with the provided values.
|
static javax.json.JsonArray |
arrayOrEmpty(javax.json.JsonObject json,
String key)
Retrieve a value as an array, or return the empty array if key is not present or if the value is the wrong type.
|
static boolean |
hasNonNull(@NotNull javax.json.JsonObject json,
String key)
Convenience method to check to avoid type errors when getting a typed value backed by a JsonValue.NULL.
|
static JavaxJson.KeyCursor |
key(String key)
Begin a key-value pair without providing a value argument.
|
static JavaxJson.Key |
key(String key,
Object value)
Creates a key-value pair for use with
obj(Key...). |
static <R> List<R> |
mapArrayOfObjects(javax.json.JsonArray jsonArray,
Function<javax.json.JsonObject,R> mapFunction)
Filters and maps the provided
JsonArray into a List<JsonObject>, then applies the provided
mapFunction to each result to return a typed list. |
static <R> List<R> |
mapArrayOfObjects(javax.json.JsonArray jsonArray,
Function<javax.json.JsonObject,R> mapFunction,
boolean discardNulls)
Filters and maps the provided
JsonArray into a List<JsonObject>, then applies the provided
mapFunction to each result to return a typed list. |
static List<String> |
mapArrayOfStrings(javax.json.JsonArray jsonArray)
Filters and maps the provided
JsonArray into a List<String>. |
static <R> List<R> |
mapArrayOfStrings(javax.json.JsonArray jsonArray,
Function<String,R> mapFunction)
Filters and maps the provided
JsonArray into a List<String>, then applies the provided mapFunction
to each result to return a typed list. |
static <R> List<R> |
mapArrayOfStrings(javax.json.JsonArray jsonArray,
Function<String,R> mapFunction,
boolean discardNulls)
Filters and maps the provided
JsonArray into a List<String>, then applies the provided mapFunction
to each result to return a typed list. |
static <R> List<R> |
mapObjectValues(javax.json.JsonObject jsonObject,
BiFunction<String,javax.json.JsonObject,R> mapBiFunction,
boolean discardNulls)
Filters and maps the provided
JsonObject into a Map<String, JsonObject>, then applies the provided
mapBiFunction to each result pair to return a typed list. |
static boolean |
nonDefaultValue(@Nullable javax.json.JsonValue value,
@NotNull javax.json.JsonValue defaultValue)
Return true if the value is not equal to the provided default value.
|
static boolean |
nonEmptyValue(@Nullable javax.json.JsonValue value)
To keep things simple and concise, the JSON CND format does not need to serialize null values, empty arrays, or
empty objects.
|
static JavaxJson.Obj |
obj(JavaxJson.Key... keys)
Create an object with the provided key-value pairs.
|
static JavaxJson.Obj |
obj(javax.json.JsonObject jsonObject)
Create an object, and add all the keys from the provided json object to it.
|
static JavaxJson.Obj |
obj(Map<?,?> map)
Create an object, and add all the keys from the provided map to it.
|
static javax.json.JsonObject |
objectOrEmpty(javax.json.JsonObject json,
String key)
Retrieve a value as an object, or return the empty object if key is not present or if the value is the wrong type.
|
static Optional<javax.json.JsonArray> |
optArray(javax.json.JsonObject json,
String key)
Retrieve a value as an array if the specified key is present, or empty() if not.
|
static Optional<javax.json.JsonObject> |
optObject(javax.json.JsonObject json,
String key)
Retrieve a value as an object if the specified key is present, or empty() if not.
|
static <R> List<R> |
parseFromArray(@NotNull javax.json.JsonArray jsonArray,
Fun.ThrowingFunction<String,R> parser,
@Nullable BiConsumer<String,Exception> errorConsumer)
Parse string elements of an array into arbitrary objects, (like URLs).
|
static @NotNull javax.json.JsonObject |
shallowMergeObjects(@Nullable javax.json.JsonObject base,
@Nullable javax.json.JsonObject overlay)
Merge an overlay json object's entries into a base json object, replacing values
for duplicate keys.
|
static Object |
unwrap(javax.json.JsonValue jsonValue)
This method performs the reverse of
wrap(Object). |
static List<Object> |
unwrapArray(javax.json.JsonArray jsonArray)
Supports
unwrap(JsonValue) for typed unwrapping of JsonArray to List<Object>. |
static Map<String,Object> |
unwrapObject(javax.json.JsonObject jsonObject)
Supports
unwrap(JsonValue) for typed unwrapping of JsonObject to Map<String, Object>. |
static JavaxJson.Value |
val(Object value)
Ensures that an object reference is wrapped appropriately for use in the DSL.
|
static javax.json.JsonValue |
wrap(Object object)
Ensures that a Java typed object is wrapped with the appropriate
JsonValue type. |
public static boolean nonEmptyValue(@Nullable
@Nullable javax.json.JsonValue value)
JsonCnd.DefinitionToken values to
the JSON stream.value - the JsonValue to testpublic static boolean nonDefaultValue(@Nullable
@Nullable javax.json.JsonValue value,
@NotNull
@NotNull javax.json.JsonValue defaultValue)
value - the JsonValue to testdefaultValue - the default JsonValue to test againstpublic static javax.json.JsonValue wrap(Object object)
JsonValue type.
Performs the reverse of unwrap(JsonValue).object - the Java type to wrappublic static Object unwrap(javax.json.JsonValue jsonValue)
wrap(Object).
Unwraps a JsonValue to its associated non-Json value.
JsonString to String,
JsonNumber to Number,
JsonValue.NULL to null,
JsonValue.TRUE to true,
JsonValue.FALSE to false,
JsonArray to List<Object>,
JsonObject to Map<String, Object>.jsonValue - the wrapped JsonValuepublic static Map<String,Object> unwrapObject(javax.json.JsonObject jsonObject)
unwrap(JsonValue) for typed unwrapping of JsonObject to Map<String, Object>.jsonObject - the json object to unwrappublic static List<Object> unwrapArray(javax.json.JsonArray jsonArray)
unwrap(JsonValue) for typed unwrapping of JsonArray to List<Object>.jsonArray - the json array to unwrap@NotNull
public static @NotNull javax.json.JsonObject shallowMergeObjects(@Nullable
@Nullable javax.json.JsonObject base,
@Nullable
@Nullable javax.json.JsonObject overlay)
base - the base json objectoverlay - the overlay json objectpublic static JavaxJson.Value val(Object value)
value - null, an instance of JavaxJson.HasValue, or some type supported by wrap(Object).public static JavaxJson.Obj obj(JavaxJson.Key... keys)
keys - 0-many key-value pairspublic static JavaxJson.Obj obj(javax.json.JsonObject jsonObject)
jsonObject - a starting pointpublic static JavaxJson.Obj obj(Map<?,?> map)
map - a starting pointpublic static JavaxJson.Key key(String key, Object value)
obj(Key...). See also JavaxJson.Obj.key(String, Object).key - the keyvalue - the valuepublic static JavaxJson.KeyCursor key(String key)
val(Object) must be called to provide a value
for the key-value pair before more keys are appended.key - the keypublic static JavaxJson.Arr arr(Object... values)
values - the value elements of the arraypublic static Optional<javax.json.JsonObject> optObject(javax.json.JsonObject json, String key)
json - the object to retrieve an object value fromkey - the array's keypublic static javax.json.JsonObject objectOrEmpty(javax.json.JsonObject json,
String key)
json - the object to retrieve an object value fromkey - the key to retrievepublic static Optional<javax.json.JsonArray> optArray(javax.json.JsonObject json, String key)
json - the object to retrieve an array fromkey - the array's keypublic static javax.json.JsonArray arrayOrEmpty(javax.json.JsonObject json,
String key)
json - the object to retrieve an array value fromkey - the key to retrievepublic static List<String> mapArrayOfStrings(javax.json.JsonArray jsonArray)
JsonArray into a List<String>.jsonArray - the array of stringspublic static <R> List<R> mapArrayOfStrings(javax.json.JsonArray jsonArray, Function<String,R> mapFunction)
JsonArray into a List<String>, then applies the provided mapFunction
to each result to return a typed list.R - the mapFunction result typejsonArray - the input arraymapFunction - the function mapping String to Rpublic static <R> List<R> mapArrayOfStrings(javax.json.JsonArray jsonArray, Function<String,R> mapFunction, boolean discardNulls)
JsonArray into a List<String>, then applies the provided mapFunction
to each result to return a typed list.R - the mapFunction result typejsonArray - the input arraymapFunction - the function mapping String to RdiscardNulls - true to filter out null results returned by the mapFunction (default false).public static <R> List<R> mapArrayOfObjects(javax.json.JsonArray jsonArray, Function<javax.json.JsonObject,R> mapFunction)
JsonArray into a List<JsonObject>, then applies the provided
mapFunction to each result to return a typed list.R - the mapFunction result typejsonArray - the input arraymapFunction - the function mapping JsonObject to Rpublic static <R> List<R> mapArrayOfObjects(javax.json.JsonArray jsonArray, Function<javax.json.JsonObject,R> mapFunction, boolean discardNulls)
JsonArray into a List<JsonObject>, then applies the provided
mapFunction to each result to return a typed list.R - the mapFunction result typejsonArray - the input arraymapFunction - the function mapping JsonObject to RdiscardNulls - true to filter out null results returned by the mapFunction (default false).public static <R> List<R> mapObjectValues(javax.json.JsonObject jsonObject, BiFunction<String,javax.json.JsonObject,R> mapBiFunction, boolean discardNulls)
JsonObject into a Map<String, JsonObject>, then applies the provided
mapBiFunction to each result pair to return a typed list.R - the mapBiFunction result typejsonObject - the input objectmapBiFunction - the bifunction mapping (String, JsonObject) pairs to RdiscardNulls - true to filter out null results returned by the mapFunction (default false).public static <R> List<R> parseFromArray(@NotNull @NotNull javax.json.JsonArray jsonArray, @NotNull Fun.ThrowingFunction<String,R> parser, @Nullable @Nullable BiConsumer<String,Exception> errorConsumer)
R - the mapFunction result typejsonArray - the array of stringsparser - the parser functionerrorConsumer - an optional error handlerFun.composeTry1(Function, Supplier, Fun.ThrowingFunction, BiConsumer)public static boolean hasNonNull(@NotNull
@NotNull javax.json.JsonObject json,
String key)
json - the json object to check a key on.key - the key to check for presence and non-nullness.Copyright © 2017–2020. All rights reserved.