简体   繁体   中英

Serialize immutable classes in GWT

I need to return object from client which is immutable by design (contains only public final fields). In GWT, looks like this is not possible?

I created successor of ImageMetadata_CustomFieldSerializer and override methods:

- instantiateInstance
- serialize

but still my final objects are not initialized (default constructor is invoked)

In general, the CustomFieldSerializer must contain special static methods in order to work properly.

Then special static methods need to be added:

public static void deserialize(SerializationStreamReader streamReader, MyObject instance) throws SerializationException {
    //...
}

public static void serialize(SerializationStreamWriter streamWriter, MyObject instance) throws SerializationException {
   //...
}

public static MyObject instantiate(SerializationStreamReader streamReader) throws SerializationException {
   //...
}

these methods contain code to serialize/deserialize MyObject from SerializationStream.

and in overridden methods it is possible to re-use the static ones.

Hope that helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM