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 1.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. /*
  2. @VaadinApache2LicenseForJavaFiles@
  3. */
  4. package com.vaadin.terminal.gwt.client.communication;
  5. import com.google.gwt.core.client.GWT;
  6. import com.google.gwt.json.client.JSONObject;
  7. import com.google.gwt.json.client.JSONValue;
  8. import com.vaadin.shared.communication.URLReference;
  9. import com.vaadin.terminal.gwt.client.ApplicationConnection;
  10. public class URLReference_Serializer implements JSONSerializer<URLReference> {
  11. // setURL() -> uRL as first char becomes lower case...
  12. private static final String URL_FIELD = "uRL";
  13. @Override
  14. public URLReference deserialize(Type type, JSONValue jsonValue,
  15. ApplicationConnection connection) {
  16. URLReference reference = GWT.create(URLReference.class);
  17. JSONObject json = (JSONObject) jsonValue;
  18. if (json.containsKey(URL_FIELD)) {
  19. JSONValue jsonURL = json.get(URL_FIELD);
  20. String URL = (String) JsonDecoder.decodeValue(
  21. new Type(String.class.getName(), null), jsonURL, null,
  22. connection);
  23. reference.setURL(connection.translateVaadinUri(URL));
  24. }
  25. return reference;
  26. }
  27. @Override
  28. public JSONValue serialize(URLReference value,
  29. ApplicationConnection connection) {
  30. JSONObject json = new JSONObject();
  31. json.put(URL_FIELD,
  32. JsonEncoder.encode(value.getURL(), true, connection));
  33. return json;
  34. }
  35. }