You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

JSONSerializer.java 2.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /*
  2. @VaadinApache2LicenseForJavaFiles@
  3. */
  4. package com.vaadin.terminal.gwt.client.communication;
  5. import com.google.gwt.json.client.JSONObject;
  6. import com.vaadin.terminal.gwt.client.ApplicationConnection;
  7. import com.vaadin.terminal.gwt.client.ConnectorMap;
  8. import com.vaadin.terminal.gwt.server.JsonCodec;
  9. /**
  10. * Implementors of this interface knows how to serialize an Object of a given
  11. * type to JSON and how to deserialize the JSON back into an object.
  12. *
  13. * The {@link #serialize(Object, ConnectorMap)} and
  14. * {@link #deserialize(JSONObject, ConnectorMap)} methods must be symmetric so
  15. * they can be chained and produce the original result (or an equal result).
  16. *
  17. * Each {@link JSONSerializer} implementation can handle an object of a single
  18. * type - see {@link SerializerMap}.
  19. *
  20. * @since 7.0
  21. */
  22. public interface JSONSerializer<T> {
  23. /**
  24. * Creates and deserializes an object received from the server. Must be
  25. * compatible with {@link #serialize(Object, ConnectorMap)} and also with
  26. * the server side
  27. * {@link JsonCodec#encode(Object, com.vaadin.terminal.gwt.server.PaintableIdMapper)}
  28. * .
  29. *
  30. * @param jsonValue
  31. * JSON map from property name to property value
  32. * @param idMapper
  33. * mapper from paintable id to paintable, used to decode
  34. * references to paintables
  35. * @return A deserialized object
  36. */
  37. T deserialize(JSONObject jsonValue, ConnectorMap idMapper,
  38. ApplicationConnection connection);
  39. /**
  40. * Serialize the given object into JSON. Must be compatible with
  41. * {@link #deserialize(JSONObject, ConnectorMap)} and also with the server
  42. * side
  43. * {@link JsonCodec#decode(com.vaadin.external.json.JSONArray, com.vaadin.terminal.gwt.server.PaintableIdMapper)}
  44. *
  45. * @param value
  46. * The object to serialize
  47. * @param idMapper
  48. * mapper from paintable id to paintable, used to decode
  49. * references to paintables
  50. * @return A JSON serialized version of the object
  51. */
  52. JSONObject serialize(T value, ConnectorMap idMapper,
  53. ApplicationConnection connection);
  54. }