import java.util.concurrent.ConcurrentMap;
import com.vaadin.server.communication.DateSerializer;
-import com.vaadin.server.communication.JsonSerializer;
+import com.vaadin.server.communication.JSONSerializer;
import com.vaadin.shared.Connector;
import com.vaadin.shared.JsonConstants;
import com.vaadin.shared.communication.UidlValue;
*/
private static Map<String, Class<?>> transportTypeToType = new HashMap<String, Class<?>>();
- private static Map<Class<?>, JsonSerializer<?>> customSerializers = new HashMap<Class<?>, JsonSerializer<?>>();
+ private static Map<Class<?>, JSONSerializer<?>> customSerializers = new HashMap<Class<?>, JSONSerializer<?>>();
static {
customSerializers.put(Date.class, new DateSerializer());
}
private static JsonValue serializeJson(Object value,
ConnectorTracker connectorTracker) {
- JsonSerializer serializer = customSerializers.get(value.getClass());
+ JSONSerializer serializer = customSerializers.get(value.getClass());
return serializer.serialize(value, connectorTracker);
}
* @since 7.2
* @author Vaadin Ltd
*/
-public class DateSerializer implements JsonSerializer<Date> {
+public class DateSerializer implements JSONSerializer<Date> {
@Override
public Date deserialize(Type type, JsonValue jsonValue,
--- /dev/null
+/*
+ * Copyright 2000-2014 Vaadin Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package com.vaadin.server.communication;
+
+import java.lang.reflect.Type;
+
+import com.vaadin.ui.ConnectorTracker;
+import elemental.json.JsonValue;
+
+/**
+ * Implementors of this interface knows how to serialize an Object of a given
+ * type to JSON and how to deserialize the JSON back into an object.
+ * <p>
+ * The {@link #serialize(Object, ConnectorTracker)} and
+ * {@link #deserialize(Type, JsonValue, ConnectorTracker)} methods must be
+ * symmetric so they can be chained and produce the original result (or an equal
+ * result).
+ * <p>
+ * Each {@link JSONSerializer} implementation can handle an object of a single
+ * type.
+ * <p>
+ * This is the server side interface, see
+ * com.vaadin.client.communication.JSONSerializer for the client side interface.
+ *
+ * @since 7.2
+ * @author Vaadin Ltd
+ */
+public interface JSONSerializer<T> {
+ /**
+ * Creates and deserializes an object received from the client. Must be
+ * compatible with {@link #serialize(Object, ConnectorTracker)} and also
+ * with the client side com.vaadin.client.communication.JSONSerializer.
+ *
+ * @param type
+ * The expected return type
+ * @param jsonValue
+ * the value from the JSON
+ * @param connectorTracker
+ * the connector tracker instance for the UI
+ * @return A deserialized object
+ */
+ T deserialize(Type type, JsonValue jsonValue, ConnectorTracker connectorTracker);
+
+ /**
+ * Serialize the given object into JSON. Must be compatible with
+ * {@link #deserialize(Type, JsonValue, ConnectorTracker)} and the client side
+ * com.vaadin.client.communication.JSONSerializer
+ *
+ * @param value
+ * The object to serialize
+ * @param connectorTracker
+ * The connector tracker instance for the UI
+ * @return A JSON serialized version of the object
+ */
+ JsonValue serialize(T value, ConnectorTracker connectorTracker);
+
+}
+++ /dev/null
-/*
- * Copyright 2000-2014 Vaadin Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may not
- * use this file except in compliance with the License. You may obtain a copy of
- * the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
- * License for the specific language governing permissions and limitations under
- * the License.
- */
-package com.vaadin.server.communication;
-
-import java.lang.reflect.Type;
-
-import com.vaadin.ui.ConnectorTracker;
-import elemental.json.JsonValue;
-
-/**
- * Implementors of this interface knows how to serialize an Object of a given
- * type to JSON and how to deserialize the JSON back into an object.
- * <p>
- * The {@link #serialize(Object, ConnectorTracker)} and
- * {@link #deserialize(Type, JsonValue, ConnectorTracker)} methods must be
- * symmetric so they can be chained and produce the original result (or an equal
- * result).
- * <p>
- * Each {@link JsonSerializer} implementation can handle an object of a single
- * type.
- * <p>
- * This is the server side interface, see
- * com.vaadin.client.communication.JSONSerializer for the client side interface.
- *
- * @since 7.2
- * @author Vaadin Ltd
- */
-public interface JsonSerializer<T> {
- /**
- * Creates and deserializes an object received from the client. Must be
- * compatible with {@link #serialize(Object, ConnectorTracker)} and also
- * with the client side com.vaadin.client.communication.JSONSerializer.
- *
- * @param type
- * The expected return type
- * @param jsonValue
- * the value from the JSON
- * @param connectorTracker
- * the connector tracker instance for the UI
- * @return A deserialized object
- */
- T deserialize(Type type, JsonValue jsonValue, ConnectorTracker connectorTracker);
-
- /**
- * Serialize the given object into JSON. Must be compatible with
- * {@link #deserialize(Type, JsonValue, ConnectorTracker)} and the client side
- * com.vaadin.client.communication.JSONSerializer
- *
- * @param value
- * The object to serialize
- * @param connectorTracker
- * The connector tracker instance for the UI
- * @return A JSON serialized version of the object
- */
- JsonValue serialize(T value, ConnectorTracker connectorTracker);
-
-}
--- /dev/null
+package com.vaadin.server;
+
+/*
+ * Copyright 2000-2014 Vaadin Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+
+import java.lang.reflect.Type;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Map;
+
+import junit.framework.AssertionFailedError;
+import junit.framework.TestCase;
+
+import com.vaadin.server.JsonCodec.BeanProperty;
+import com.vaadin.shared.communication.UidlValue;
+import com.vaadin.shared.ui.splitpanel.AbstractSplitPanelState;
+
+import elemental.json.Json;
+import elemental.json.JsonArray;
+import elemental.json.JsonException;
+import elemental.json.JsonValue;
+
+/**
+ * Tests for {@link JsonCodec}
+ *
+ * @author Vaadin Ltd
+ * @since 7.0
+ *
+ */
+public class JSONSerializerTest extends TestCase {
+ HashMap<String, AbstractSplitPanelState> stringToStateMap;
+ HashMap<AbstractSplitPanelState, String> stateToStringMap;
+
+ public void testStringToBeanMapSerialization() throws Exception {
+ Type mapType = getClass().getDeclaredField("stringToStateMap")
+ .getGenericType();
+ stringToStateMap = new HashMap<String, AbstractSplitPanelState>();
+ AbstractSplitPanelState s = new AbstractSplitPanelState();
+ AbstractSplitPanelState s2 = new AbstractSplitPanelState();
+ s.caption = "State 1";
+ s.id = "foo";
+ s2.caption = "State 2";
+ s2.id = "bar";
+ stringToStateMap.put("string - state 1", s);
+ stringToStateMap.put("String - state 2", s2);
+
+ JsonValue encodedMap = JsonCodec.encode(stringToStateMap, null, mapType,
+ null).getEncodedValue();
+
+ ensureDecodedCorrectly(stringToStateMap, encodedMap, mapType);
+ }
+
+ public void testBeanToStringMapSerialization() throws Exception {
+ Type mapType = getClass().getDeclaredField("stateToStringMap")
+ .getGenericType();
+ stateToStringMap = new HashMap<AbstractSplitPanelState, String>();
+ AbstractSplitPanelState s = new AbstractSplitPanelState();
+ AbstractSplitPanelState s2 = new AbstractSplitPanelState();
+ s.caption = "State 1";
+ s2.caption = "State 2";
+ stateToStringMap.put(s, "string - state 1");
+ stateToStringMap.put(s2, "String - state 2");
+
+ JsonValue encodedMap = JsonCodec.encode(stateToStringMap, null, mapType,
+ null).getEncodedValue();
+
+ ensureDecodedCorrectly(stateToStringMap, encodedMap, mapType);
+ }
+
+ public void testNullLegacyValue() throws JsonException {
+ JsonArray inputArray = Json.createArray();
+ inputArray.set(0, "n");
+ inputArray.set(1, Json.createNull());
+ UidlValue decodedObject = (UidlValue) JsonCodec.decodeInternalType(
+ UidlValue.class, true, inputArray, null);
+ assertNull(decodedObject.getValue());
+ }
+
+ public void testNullTypeOtherValue() {
+ try {
+ JsonArray inputArray = Json.createArray();
+ inputArray.set(0, "n");
+ inputArray.set(1, "a");
+ UidlValue decodedObject = (UidlValue) JsonCodec.decodeInternalType(
+ UidlValue.class, true, inputArray, null);
+
+ throw new AssertionFailedError("No JsonException thrown");
+ } catch (JsonException e) {
+ // Should throw exception
+ }
+ }
+
+ private void ensureDecodedCorrectly(Object original, JsonValue encoded,
+ Type type) throws Exception {
+ Object serverSideDecoded = JsonCodec.decodeInternalOrCustomType(type,
+ encoded, null);
+ assertTrue("Server decoded", equals(original, serverSideDecoded));
+
+ }
+
+ private boolean equals(Object o1, Object o2) throws Exception {
+ if (o1 == null) {
+ return (o2 == null);
+ }
+ if (o2 == null) {
+ return false;
+ }
+
+ if (o1 instanceof Map) {
+ if (!(o2 instanceof Map)) {
+ return false;
+ }
+ return equalsMap((Map) o1, (Map) o2);
+ }
+
+ if (o1.getClass() != o2.getClass()) {
+ return false;
+ }
+
+ if (o1 instanceof Collection || o1 instanceof Number
+ || o1 instanceof String) {
+ return o1.equals(o2);
+ }
+
+ return equalsBean(o1, o2);
+ }
+
+ private boolean equalsBean(Object o1, Object o2) throws Exception {
+ for (BeanProperty property : JsonCodec.getProperties(o1.getClass())) {
+ Object c1 = property.getValue(o1);
+ Object c2 = property.getValue(o2);
+ if (!equals(c1, c2)) {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ private boolean equalsMap(Map o1, Map o2) throws Exception {
+ for (Object key1 : o1.keySet()) {
+ Object key2 = key1;
+ if (!(o2.containsKey(key2))) {
+ // Try to fins a key that is equal
+ for (Object k2 : o2.keySet()) {
+ if (equals(key1, k2)) {
+ key2 = k2;
+ break;
+ }
+ }
+ }
+ if (!equals(o1.get(key1), o2.get(key2))) {
+ return false;
+ }
+
+ }
+ return true;
+ }
+}
+++ /dev/null
-package com.vaadin.server;
-
-/*
- * Copyright 2000-2014 Vaadin Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may not
- * use this file except in compliance with the License. You may obtain a copy of
- * the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
- * License for the specific language governing permissions and limitations under
- * the License.
- */
-
-import java.lang.reflect.Type;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.Map;
-
-import junit.framework.AssertionFailedError;
-import junit.framework.TestCase;
-
-import com.vaadin.server.JsonCodec.BeanProperty;
-import com.vaadin.shared.communication.UidlValue;
-import com.vaadin.shared.ui.splitpanel.AbstractSplitPanelState;
-
-import elemental.json.Json;
-import elemental.json.JsonArray;
-import elemental.json.JsonException;
-import elemental.json.JsonValue;
-
-/**
- * Tests for {@link JsonCodec}
- *
- * @author Vaadin Ltd
- * @since 7.0
- *
- */
-public class JsonSerializerTest extends TestCase {
- HashMap<String, AbstractSplitPanelState> stringToStateMap;
- HashMap<AbstractSplitPanelState, String> stateToStringMap;
-
- public void testStringToBeanMapSerialization() throws Exception {
- Type mapType = getClass().getDeclaredField("stringToStateMap")
- .getGenericType();
- stringToStateMap = new HashMap<String, AbstractSplitPanelState>();
- AbstractSplitPanelState s = new AbstractSplitPanelState();
- AbstractSplitPanelState s2 = new AbstractSplitPanelState();
- s.caption = "State 1";
- s.id = "foo";
- s2.caption = "State 2";
- s2.id = "bar";
- stringToStateMap.put("string - state 1", s);
- stringToStateMap.put("String - state 2", s2);
-
- JsonValue encodedMap = JsonCodec.encode(stringToStateMap, null, mapType,
- null).getEncodedValue();
-
- ensureDecodedCorrectly(stringToStateMap, encodedMap, mapType);
- }
-
- public void testBeanToStringMapSerialization() throws Exception {
- Type mapType = getClass().getDeclaredField("stateToStringMap")
- .getGenericType();
- stateToStringMap = new HashMap<AbstractSplitPanelState, String>();
- AbstractSplitPanelState s = new AbstractSplitPanelState();
- AbstractSplitPanelState s2 = new AbstractSplitPanelState();
- s.caption = "State 1";
- s2.caption = "State 2";
- stateToStringMap.put(s, "string - state 1");
- stateToStringMap.put(s2, "String - state 2");
-
- JsonValue encodedMap = JsonCodec.encode(stateToStringMap, null, mapType,
- null).getEncodedValue();
-
- ensureDecodedCorrectly(stateToStringMap, encodedMap, mapType);
- }
-
- public void testNullLegacyValue() throws JsonException {
- JsonArray inputArray = Json.createArray();
- inputArray.set(0, "n");
- inputArray.set(1, Json.createNull());
- UidlValue decodedObject = (UidlValue) JsonCodec.decodeInternalType(
- UidlValue.class, true, inputArray, null);
- assertNull(decodedObject.getValue());
- }
-
- public void testNullTypeOtherValue() {
- try {
- JsonArray inputArray = Json.createArray();
- inputArray.set(0, "n");
- inputArray.set(1, "a");
- UidlValue decodedObject = (UidlValue) JsonCodec.decodeInternalType(
- UidlValue.class, true, inputArray, null);
-
- throw new AssertionFailedError("No JsonException thrown");
- } catch (JsonException e) {
- // Should throw exception
- }
- }
-
- private void ensureDecodedCorrectly(Object original, JsonValue encoded,
- Type type) throws Exception {
- Object serverSideDecoded = JsonCodec.decodeInternalOrCustomType(type,
- encoded, null);
- assertTrue("Server decoded", equals(original, serverSideDecoded));
-
- }
-
- private boolean equals(Object o1, Object o2) throws Exception {
- if (o1 == null) {
- return (o2 == null);
- }
- if (o2 == null) {
- return false;
- }
-
- if (o1 instanceof Map) {
- if (!(o2 instanceof Map)) {
- return false;
- }
- return equalsMap((Map) o1, (Map) o2);
- }
-
- if (o1.getClass() != o2.getClass()) {
- return false;
- }
-
- if (o1 instanceof Collection || o1 instanceof Number
- || o1 instanceof String) {
- return o1.equals(o2);
- }
-
- return equalsBean(o1, o2);
- }
-
- private boolean equalsBean(Object o1, Object o2) throws Exception {
- for (BeanProperty property : JsonCodec.getProperties(o1.getClass())) {
- Object c1 = property.getValue(o1);
- Object c2 = property.getValue(o2);
- if (!equals(c1, c2)) {
- return false;
- }
- }
- return true;
- }
-
- private boolean equalsMap(Map o1, Map o2) throws Exception {
- for (Object key1 : o1.keySet()) {
- Object key2 = key1;
- if (!(o2.containsKey(key2))) {
- // Try to fins a key that is equal
- for (Object k2 : o2.keySet()) {
- if (equals(key1, k2)) {
- key2 = k2;
- break;
- }
- }
- }
- if (!equals(o1.get(key1), o2.get(key2))) {
- return false;
- }
-
- }
- return true;
- }
-}
"com\\.vaadin\\.server\\.communication\\.PushRequestHandler.*",
"com\\.vaadin\\.server\\.communication\\.PushHandler.*", // PushHandler
"com\\.vaadin\\.server\\.communication\\.DateSerializer", //
- "com\\.vaadin\\.server\\.communication\\.JsonSerializer", //
+ "com\\.vaadin\\.server\\.communication\\.JSONSerializer", //
// and its inner classes do not need to be serializable
"com\\.vaadin\\.util\\.SerializerHelper", // fully static
// class level filtering, also affecting nested classes and