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 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 Type
    Method
    Description
    static elemental.json.JsonValue
    toJson(Object bean)

    Converts a Java bean, JsonSerializable instance, String, wrapper of primitive type or enum to a JsonValue.

    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
    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.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • toJson

      public static elemental.json.JsonValue toJson(Object bean)

      Converts a Java bean, JsonSerializable instance, String, wrapper of primitive type or enum to a JsonValue.

      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 a JsonArray, 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 to

      json - the json representation of the object

      Returns:

      the deserialized object, or null if the input json is null

    • 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 array

      json - the json representation of the objects

      Returns:

      a modifiable list of converted objects. Returns an empty list if the input array is null