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

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /*
  2. * Copyright 2011 Vaadin Ltd.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License"); you may not
  5. * use this file except in compliance with the License. You may obtain a copy of
  6. * the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  12. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  13. * License for the specific language governing permissions and limitations under
  14. * the License.
  15. */
  16. package com.vaadin.terminal.gwt.client.communication;
  17. import com.google.gwt.json.client.JSONObject;
  18. import com.google.gwt.json.client.JSONValue;
  19. import com.vaadin.terminal.gwt.client.ApplicationConnection;
  20. import com.vaadin.terminal.gwt.client.ConnectorMap;
  21. /**
  22. * Implementors of this interface knows how to serialize an Object of a given
  23. * type to JSON and how to deserialize the JSON back into an object.
  24. *
  25. * The {@link #serialize(Object, ConnectorMap)} and
  26. * {@link #deserialize(JSONObject, ConnectorMap)} methods must be symmetric so
  27. * they can be chained and produce the original result (or an equal result).
  28. *
  29. * Each {@link JSONSerializer} implementation can handle an object of a single
  30. * type - see {@link SerializerMap}.
  31. *
  32. * @since 7.0
  33. */
  34. public interface JSONSerializer<T> {
  35. /**
  36. * Creates and deserializes an object received from the server. Must be
  37. * compatible with {@link #serialize(Object, ConnectorMap)} and also with
  38. * the server side JsonCodec.encode(Object,
  39. * com.vaadin.terminal.gwt.server.PaintableIdMapper) .
  40. *
  41. * @param jsonValue
  42. * JSON map from property name to property value
  43. * @return A deserialized object
  44. */
  45. T deserialize(Type type, JSONValue jsonValue,
  46. ApplicationConnection connection);
  47. /**
  48. * Serialize the given object into JSON. Must be compatible with
  49. * {@link #deserialize(JSONObject, ConnectorMap)} and also with the server
  50. * side JsonCodec.decode(com.vaadin.external.json.JSONArray,
  51. * com.vaadin.terminal.gwt.server.PaintableIdMapper)
  52. *
  53. * @param value
  54. * The object to serialize
  55. * @return A JSON serialized version of the object
  56. */
  57. JSONValue serialize(T value, ApplicationConnection connection);
  58. }