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

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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 target
  33. * The object to write the deserialized values to
  34. * @param idMapper
  35. * mapper from paintable id to paintable, used to decode
  36. * references to paintables
  37. * @return A deserialized object
  38. */
  39. T deserialize(JSONObject jsonValue, T target, ConnectorMap idMapper,
  40. ApplicationConnection connection);
  41. /**
  42. * Serialize the given object into JSON. Must be compatible with
  43. * {@link #deserialize(JSONObject, ConnectorMap)} and also with the server
  44. * side
  45. * {@link JsonCodec#decode(com.vaadin.external.json.JSONArray, com.vaadin.terminal.gwt.server.PaintableIdMapper)}
  46. *
  47. * @param value
  48. * The object to serialize
  49. * @param idMapper
  50. * mapper from paintable id to paintable, used to decode
  51. * references to paintables
  52. * @return A JSON serialized version of the object
  53. */
  54. JSONObject serialize(T value, ConnectorMap idMapper,
  55. ApplicationConnection connection);
  56. }