How to send any Serializable object to the client side in GWT

Imagine that you want to send any Serializable class to the client side of your GWT application using DTO:

public class MyDTO implements Serializable { public Serializable value; } 

In addition, everything that is used as a value will be checked if it is installed before it is set. GWT really throws a couple warnings to the dev console:

 DEBUG: com.example.app.shared.MyDTO. DEBUG: Analyzing the fields of type 'com.example.app.shared.MyDTO' that qualify for serialization. DEBUG: private java.io.Serializable value. DEBUG: java.io.Serializable. DEBUG: Verifying instantiability. DEBUG: java.util.ArrayList<? extends java.lang.Object>. WARN: Checking all subtypes of Object which qualify for serialization. DEBUG: com.google.gwt.validation.client.impl.PathImpl. DEBUG: Verifying instantiability. DEBUG: com.google.gwt.validation.client.impl.PathImpl. DEBUG: Analyzing the fields of type 'com.google.gwt.validation.client.impl.PathImpl' that qualify for serialization. WARN: Field 'private final java.util.List<javax.validation.Path.Node> nodes' will not be serialized because it is final. 

But! Unfortunately, this causes the GWT to throw a Serialization RPC exception when it is sent to the client side:

 com.google.gwt.user.client.rpc.SerializationException: Type 'com.example.app.shared.MyDTO' was not included in the set of types which can be serialized by this SerializationPolicy or its Class object could not be loaded. For security purposes, this type will not be serialized.: instance = com.example.app.shared.MyDTO@577f52ed at com.google.gwt.user.server.rpc.impl.ServerSerializationStreamWriter.serialize(ServerSerializationStreamWriter.java:619) at com.google.gwt.user.client.rpc.impl.AbstractSerializationStreamWriter.writeObject(AbstractSerializationStreamWriter.java:126) at com.google.gwt.user.client.rpc.core.java.util.Collection_CustomFieldSerializerBase.serialize(Collection_CustomFieldSerializerBase.java:44) ... 

Bottomline: How do you prevent GWT from fitting to Serializable subtypes?

EDIT:

I ended up creating a subclass for each class I needed.

+4
source share
1 answer

GWT must know the type of the class at compile time. Therefore, you need to specify the exact class that implements Serializable.

To overcome, I think you can use the card to send your data in the form of key-value pairs.

+5
source

Source: https://habr.com/ru/post/1402829/


All Articles