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

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