Serializing immutable java classes to actionscript with LCDS

杀马特。学长 韩版系。学妹 提交于 2019-12-21 04:49:10

问题


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?

Many thanks


回答1:


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.




回答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




回答3:


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



来源:https://stackoverflow.com/questions/1524326/serializing-immutable-java-classes-to-actionscript-with-lcds

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!