com.vaadin.flow.internal.
Class JsonUtils
- java.lang.Object
-
- com.vaadin.flow.internal.JsonUtils
-
public final class JsonUtils extends Object
Helpers for using
elemental.json
.Since:
1.0
Author:
Vaadin Ltd
-
-
Method Summary
All Methods Modifier and Type Method and Description static Collector<elemental.json.JsonValue,elemental.json.JsonArray,elemental.json.JsonArray>
asArray()
Creates a collector that collects values into a JSON array.
static elemental.json.JsonArray
createArray(elemental.json.JsonValue... values)
Creates a new JSON array with the given values.
static <T> elemental.json.JsonObject
createObject(Map<String,T> map, Function<T,elemental.json.JsonValue> itemToJson)
Converts the given map into a JSON object by converting each map value to a JSON value.
static boolean
jsonEquals(elemental.json.JsonValue a, elemental.json.JsonValue b)
Compares two json values for deep equality.
static DoubleStream
numberStream(elemental.json.JsonArray array)
Creates a double stream from a JSON array of numbers.
static Stream<elemental.json.JsonObject>
objectStream(elemental.json.JsonArray array)
Creates a stream from a JSON array of objects.
static <T extends elemental.json.JsonValue>
Stream<T>stream(elemental.json.JsonArray array)
Creates a stream from a JSON array.
-
-
-
Method Detail
-
jsonEquals
public static boolean jsonEquals(elemental.json.JsonValue a, elemental.json.JsonValue b)
Compares two json values for deep equality.
This is a helper for overcoming the fact that
JsonValue
doesn't overrideObject.equals(Object)
andJsonValue.jsEquals(JsonValue)
is defined to use JavaScript semantics where arrays and objects are equals only based on identity.Parameters:
a
- the first json value to check, may not be nullb
- the second json value to check, may not be nullReturns:
true
if both json values are the same;false
otherwise
-
stream
public static <T extends elemental.json.JsonValue> Stream<T> stream(elemental.json.JsonArray array)
Creates a stream from a JSON array.
Type Parameters:
T
- the stream typeParameters:
array
- the JSON array to create a stream fromReturns:
a stream of JSON values
-
objectStream
public static Stream<elemental.json.JsonObject> objectStream(elemental.json.JsonArray array)
Creates a stream from a JSON array of objects. This method does not verify that all items in the array are actually JSON objects instead of some other JSON type.
Parameters:
array
- the JSON array to create a stream fromReturns:
a stream of JSON objects
-
numberStream
public static DoubleStream numberStream(elemental.json.JsonArray array)
Creates a double stream from a JSON array of numbers. This method does not verify that all items in the array are actually JSON numbers instead of some other JSON type.
Parameters:
array
- the JSON array to create a stream fromReturns:
a double stream of the values in the array
-
asArray
public static Collector<elemental.json.JsonValue,elemental.json.JsonArray,elemental.json.JsonArray> asArray()
Creates a collector that collects values into a JSON array.
Returns:
the collector
-
createArray
public static elemental.json.JsonArray createArray(elemental.json.JsonValue... values)
Creates a new JSON array with the given values.
Parameters:
values
- the values that should be in the created arrayReturns:
the created array
-
createObject
public static <T> elemental.json.JsonObject createObject(Map<String,T> map, Function<T,elemental.json.JsonValue> itemToJson)
Converts the given map into a JSON object by converting each map value to a JSON value.
Type Parameters:
T
- the type of the map valuesParameters:
map
- the map to convert into a JSON objectitemToJson
- callback for converting map values to JSONReturns:
the created object
-
-