How do you exclude an object property in GWT from serialization?

Is there a way to exclude primitive and object properties in a Serializable Object from GWT Serialization?

public class Provider implements Serializable{ public Provider() { } //Id like to exclude this property: private String password; // private String address1; private String address2; private String companyName; private String phone; } 
+6
java properties serialization gwt
source share
4 answers

I was hoping for something like a special annotation

I think you are looking for @GwtTransient

@GwtTransient , annotation that tells the GWT RPC to process the field, as if it was marked with a Java transient keyword, even if it is not.

This annotation means the same as the transient keyword, but it is ignored by all serialization of systems other than GWT. Typically, the transient keyword should be used in preference from this annotation. However, for types used with multiple serialization, this may be useful.

Link: @GwtTransient

+10
source share

Can't you just declare transitional?

 transient private String password; 
+6
source share

If you really want to avoid using the transient keyword, you might want to look at the Serial fields of custom fields .

In my last GWT project, I used them to serialize immutable classes, as GWT-RPC had limitations for them.

This is a poorly documented function, and the best explanation I discovered at that time was not in the GWT documentation, but on this large wogwt wiki page . You can also find some examples in the GWT package com.google.gwt.user.client.rpc.core , since GWT uses a lot of these.

Note that CustomFieldSerializers still have some issues, such as issue 2931 and release 3315 . Also, I don't like how they are defined: instead of using static methods, it would be better to let users implement the CustomFieldSerializer<T> interface. We would gain security and inheritance. But this is another discussion, and the GWT compiler can actually use these static methods to improve performance (I have not considered this).

However, this works, and it is good to have them in specific cases.

+4
source share

add transition to the field

0
source share

All Articles