private final ClientConnector connector;
private final String interfaceName;
private final String methodName;
- private final Object[] parameters;
+ private transient Object[] parameters;
private Type[] parameterTypes;
// used for sorting calls between different connectors in the same UI
// that is Serializable. On deserialization (readObject-method below)
// the process should be reversed.
+ Object[] serializedParameters = new Object[parameters.length];
// Easy way for implementing serialization & deserialization is by
// writing/parsing the object's content as string.
for (int i = 0; i < parameterTypes.length; i++) {
if (type instanceof Class<?>) {
Class<?> clazz = (Class<?>) type;
if (JsonArray.class.isAssignableFrom(clazz)) {
- parameters[i] = JsonUtil
+ serializedParameters[i] = JsonUtil
.stringify((JsonArray) parameters[i]);
+ } else {
+ serializedParameters[i] = parameters[i];
}
}
}
stream.defaultWriteObject();
+ stream.writeObject(serializedParameters);
}
private void readObject(ObjectInputStream stream) throws IOException,
// Reverses the serialization done in writeObject. Basically just
// parsing the serialized type back to the non-serializable type.
stream.defaultReadObject();
+ parameters = (Object[]) stream.readObject();
for (int i = 0; i < parameterTypes.length; i++) {
Type type = parameterTypes[i];
if (type instanceof Class<?>) {
import junit.framework.TestCase;
+import com.vaadin.server.ClientConnector;
import com.vaadin.server.ClientMethodInvocation;
import com.vaadin.server.JavaScriptCallbackHelper;
+import com.vaadin.server.JsonCodec;
import com.vaadin.ui.JavaScript.JavaScriptCallbackRpc;
import com.vaadin.util.ReflectTools;
import elemental.json.Json;
import elemental.json.JsonArray;
+import elemental.json.JsonValue;
import elemental.json.impl.JsonUtil;
public class ClientMethodSerializationTest extends TestCase {
return output;
}
+ public void testSerializeTwice() {
+ String name = "javascriptFunctionName";
+ String[] arguments = { "1", "2", "3" };
+ JsonArray args = (JsonArray) JsonCodec.encode(arguments, null,
+ Object[].class, null).getEncodedValue();
+ ClientConnector connector = null;
+
+ ClientMethodInvocation original = new ClientMethodInvocation(connector,
+ "interfaceName", JAVASCRIPT_CALLBACK_METHOD, new Object[] {
+ name, args });
+
+ ClientMethodInvocation copy = (ClientMethodInvocation) serializeAndDeserialize(original);
+ assertEquals(copy.getMethodName(), original.getMethodName());
+ assertEquals(copy.getParameters().length,
+ original.getParameters().length);
+ for (int i = 0; i < copy.getParameters().length; i++) {
+ Object originalParameter = original.getParameters()[i];
+ Object copyParameter = copy.getParameters()[i];
+ if (originalParameter instanceof JsonValue) {
+ assertEquals(((JsonValue) originalParameter).toJson(),
+ ((JsonValue) copyParameter).toJson());
+ } else {
+ assertEquals(originalParameter, copyParameter);
+ }
+ }
+ }
+
}