Package com.vaadin.flow.internal
Class JsonSerializer
- java.lang.Object
-
- com.vaadin.flow.internal.JsonSerializer
-
public final class JsonSerializer extends Object
General-purpose serializer of Java objects toJsonValue
and deserializer of JsonValue to Java objects.For internal use only. May be renamed or removed in a future release.
- Since:
- 1.0
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static elemental.json.JsonValue
toJson(Object bean)
Converts a Java bean,JsonSerializable
instance, String, wrapper of primitive type or enum to aJsonValue
.static elemental.json.JsonArray
toJson(Collection<?> beans)
Converts a collection of object into aJsonArray
, converting each item of the collection individually.static <T> T
toObject(Class<T> type, elemental.json.JsonValue json)
Converts a JsonValue to the corresponding Java object.static <T> List<T>
toObjects(Class<T> type, elemental.json.JsonArray json)
Converts a JsonArray into a collection of Java objects.
-
-
-
Method Detail
-
toJson
public static elemental.json.JsonValue toJson(Object bean)
Converts a Java bean,JsonSerializable
instance, String, wrapper of primitive type or enum to aJsonValue
.When a bean is used, a
JsonObject
is returned.- Parameters:
bean
- Java object to be converted- Returns:
- the json representation of the Java object
-
toJson
public static elemental.json.JsonArray toJson(Collection<?> beans)
Converts a collection of object into aJsonArray
, converting each item of the collection individually.- Parameters:
beans
- the collection of objects to be converted- Returns:
- the json representation of the objects in the collectios. An
empty array is returned if the input collections is
null
-
toObject
public static <T> T toObject(Class<T> type, elemental.json.JsonValue json)
Converts a JsonValue to the corresponding Java object. The Java object can be a Java bean,JsonSerializable
instance, String, wrapper of primitive types or an enum.- Type Parameters:
T
- the resulting object type- Parameters:
type
- the type of the Java object convert the json tojson
- the json representation of the object- Returns:
- the deserialized object, or
null
if the input json isnull
-
toObjects
public static <T> List<T> toObjects(Class<T> type, elemental.json.JsonArray json)
Converts a JsonArray into a collection of Java objects. The Java objects can be Java beans,JsonSerializable
instances, Strings, wrappers of primitive types or enums.- Type Parameters:
T
- the resulting objects types- Parameters:
type
- the type of the elements in the arrayjson
- the json representation of the objects- Returns:
- a modifiable list of converted objects. Returns an empty list if
the input array is
null
-
-