Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

JSONSerializer.java 2.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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.client.communication;
  17. import com.google.gwt.json.client.JSONObject;
  18. import com.google.gwt.json.client.JSONValue;
  19. import com.vaadin.client.ApplicationConnection;
  20. import com.vaadin.client.ConnectorMap;
  21. import com.vaadin.client.metadata.Type;
  22. /**
  23. * Implementors of this interface knows how to serialize an Object of a given
  24. * type to JSON and how to deserialize the JSON back into an object.
  25. *
  26. * The {@link #serialize(Object, ConnectorMap)} and
  27. * {@link #deserialize(JSONObject, ConnectorMap)} methods must be symmetric so
  28. * they can be chained and produce the original result (or an equal result).
  29. *
  30. * Each {@link JSONSerializer} implementation can handle an object of a single
  31. * type - see {@link SerializerMap}.
  32. *
  33. * @since 7.0
  34. */
  35. public interface JSONSerializer<T> {
  36. /**
  37. * Creates and deserializes an object received from the server. Must be
  38. * compatible with {@link #serialize(Object, ConnectorMap)} and also with
  39. * the server side JsonCodec.encode(Object,
  40. * com.vaadin.terminal.gwt.server.PaintableIdMapper) .
  41. *
  42. * @param jsonValue
  43. * JSON map from property name to property value
  44. * @return A deserialized object
  45. */
  46. T deserialize(Type type, JSONValue jsonValue,
  47. ApplicationConnection connection);
  48. /**
  49. * Serialize the given object into JSON. Must be compatible with
  50. * {@link #deserialize(JSONObject, ConnectorMap)} and also with the server
  51. * side JsonCodec.decode(com.vaadin.external.json.JSONArray,
  52. * com.vaadin.terminal.gwt.server.PaintableIdMapper)
  53. *
  54. * @param value
  55. * The object to serialize
  56. * @return A JSON serialized version of the object
  57. */
  58. JSONValue serialize(T value, ApplicationConnection connection);
  59. }