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.

URLReference_Serializer.java 2.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /*
  2. * Copyright 2000-2014 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.core.client.GWT;
  18. import com.google.gwt.json.client.JSONObject;
  19. import com.google.gwt.json.client.JSONValue;
  20. import com.vaadin.client.ApplicationConnection;
  21. import com.vaadin.client.metadata.Type;
  22. import com.vaadin.shared.communication.URLReference;
  23. public class URLReference_Serializer implements JSONSerializer<URLReference> {
  24. // setURL() -> uRL as first char becomes lower case...
  25. private static final String URL_FIELD = "uRL";
  26. @Override
  27. public URLReference deserialize(Type type, JSONValue jsonValue,
  28. ApplicationConnection connection) {
  29. TranslatedURLReference reference = GWT
  30. .create(TranslatedURLReference.class);
  31. reference.setConnection(connection);
  32. JSONObject json = (JSONObject) jsonValue;
  33. if (json.containsKey(URL_FIELD)) {
  34. JSONValue jsonURL = json.get(URL_FIELD);
  35. String URL = (String) JsonDecoder.decodeValue(
  36. new Type(String.class.getName(), null), jsonURL, null,
  37. connection);
  38. reference.setURL(URL);
  39. }
  40. return reference;
  41. }
  42. @Override
  43. public JSONValue serialize(URLReference value,
  44. ApplicationConnection connection) {
  45. JSONObject json = new JSONObject();
  46. // No type info required for encoding a String...
  47. json.put(URL_FIELD,
  48. JsonEncoder.encode(value.getURL(), null, connection));
  49. return json;
  50. }
  51. }