com.vaadin.flow.internal.
Class JsonSerializer
General-purpose serializer of Java objects to JsonValue
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
Modifier and TypeMethodDescriptionstatic elemental.json.JsonValue
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 a
JsonArray
, converting each item of the collection individually.static <T> T
Converts a JsonValue to the corresponding Java object.
static <T> List<T>
Converts a JsonArray into a collection of Java objects.
-
Method Details
-
toJson
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 convertedReturns:
the json representation of the Java object
-
toJson
Converts a collection of object into a
JsonArray
, converting each item of the collection individually.Parameters:
beans
- the collection of objects to be convertedReturns:
the json representation of the objects in the collectios. An empty array is returned if the input collections is
null
-
toObject
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 typeParameters:
type
- the type of the Java object convert the json tojson
- the json representation of the objectReturns:
the deserialized object, or
null
if the input json isnull
-
toObjects
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 typesParameters:
type
- the type of the elements in the arrayjson
- the json representation of the objectsReturns:
a modifiable list of converted objects. Returns an empty list if the input array is
null
-