Serializing immutable java classes to actionscript with LCDS
Asked Answered
H

3

7

I've got a complex object which is being managed by the LCDS DataServices data management and being created/updated etc using custom assemblers. The vast majority of the object hierarchy is being serialized/deserialized correctly but I've hit a stumbling block when it comes to serializing immutable java classes.

In a java only world I would use the java writeReplace and readResolve methods as this excellent blog describes: http://lingpipe-blog.com/2009/08/10/serializing-immutable-singletons-serialization-proxy/

This is how I originally wrote my java class, expecting livecycle to call the writeReplace method and duly replace the immutable class with a mutable one for serialization. However it would appear that lcds knows nothing of the writeReplace method and will only call readExternal/writeExternal ignoring readResolve and writeReplace.

Firstly, have other people found this to be the case, or am I missing something?

Secondly, has anyone come up with an appropriate method to deserialize actionscript classes into either immutable objects or singletons?

Horwath answered 6/10, 2009 at 8:39 Comment(0)
H
5

Yes, it's a common problem. Adobe recommend that the Java type that has immutable properties implements Externalizable and the equivalent ActionScript type implements IExternalizable.

Huda answered 4/11, 2009 at 8:51 Comment(1)
Thanks Graeme. I came to the same conclusion. I don't suppose you're aware of any plans for writeReplace and readResolve to be handle correctly by LCDS in the future are you?Horwath
M
2

There is no plan to handle the writeReplace and readResolve, but you can ask for a feature request http://bugs.adobe.com/jira/browse/BLZ

When implementing your custom serialization take care that you will lose some benefits like compressing numbers and identifying duplicate strings. One idea is to take a look on the actual serialization mechanism and to modify it accordingly.

However, if you are interested just in serializing the read only properties this enhancement was implemented in the BlazeDS, take a look here: http://bugs.adobe.com/jira/browse/BLZ-427

Mcclary answered 6/12, 2009 at 13:8 Comment(0)
S
1

shortest and most comprehensive answer i found: http://expertdevelopers.blogspot.com/2010/07/serializable-vs-externalizable.html

Store answered 3/11, 2011 at 22:38 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.