Wednesday, July 9, 2008

Excluding properties from Java - ActionScript serialization

Recently I have found a way to exclude a property from Java to ActionScript serialization.
We had to use this trick to prevent a property added by Hibernate on persisted objects to be serialized.

The trick is to use an undocumented (public static) method of LiveCycle Data Services / BlazeDS BeanProxy class:

static {
    flex.messaging.io.BeanProxy.addIgnoreProperty(MyClass.class, "myproperty");
}

Just specify the target class and property and it will be excluded from serialization.
Of course, this is not a very elegant way to achieve this but when you have no other choice (like in our case where we could not use a transient field) this can be handy.