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

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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. URLReference reference = GWT.create(URLReference.class);
  30. JSONObject json = (JSONObject) jsonValue;
  31. if (json.containsKey(URL_FIELD)) {
  32. JSONValue jsonURL = json.get(URL_FIELD);
  33. String URL = (String) JsonDecoder.decodeValue(
  34. new Type(String.class.getName(), null), jsonURL, null,
  35. connection);
  36. reference.setURL(connection.translateVaadinUri(URL));
  37. }
  38. return reference;
  39. }
  40. @Override
  41. public JSONValue serialize(URLReference value,
  42. ApplicationConnection connection) {
  43. JSONObject json = new JSONObject();
  44. // No type info required for encoding a String...
  45. json.put(URL_FIELD,
  46. JsonEncoder.encode(value.getURL(), null, connection));
  47. return json;
  48. }
  49. }