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.

2 comments:

ouaqa said...

At last, thanks to your post I know what to do with my similar problem.

Still, I have a noobs question : where do place this hack (which class) ?

thanks again

ozeebee said...

Hi,

we have put this code in a static block of a class that was managed by our Spring container.
If you don't use spring, you can place it in a servlet for instance.

Hope this helps