开发者

GWT classes: an annotation to prevent serialization of a field?

In GWT 1.7 I have a class used to construct object on the server side which are then used on 开发者_开发百科the client (browser) side.

On the client side I want to cache a service (in this case NumberFormat). This will be initialized lazily in a client-only method, and stored as a field object.

The problem is the Java (1.6) build tools interpret this field as needing to be serialized on the server side (even though it's never accessed on the server).

I could wrap the object in some hander client side but I'd rather specify an annotation to indicate the field will never need serializing for RPC transmission.

public class myCrossDomainObject {

  private int someSerializedField;
  private string anotherSerializedField;

  @SomeAnnotationIKnowNotWhat(..)
  private NumberFormat numberFormatterDontSerializeMe;

  // rest of class ......

}


Try

private transient NumberFormat numberFormatterDontSerializeMe;


@GwtTransient

This annotation means the same thing as the transient keyword, but it is ignored by all serialization systems other than GWT's. Usually the transient keyword should be used in preference to this annotation. However, for types used with multiple serialization systems, it can be useful.
Note that GWT will actually accept any annotation named GwtTransient for this purpose. This is done to allow libraries to support GWT serialization without creating a direct dependency on the GWT distribution.

http://www.gwtproject.org/javadoc/latest/com/google/gwt/user/client/rpc/GwtTransient.html

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜