tag:blogger.com,1999:blog-741750605858169835.post7450400251975118962..comments2024-01-24T14:53:02.919+00:00Comments on Stephen Colebourne's blog: Serialization - shared delegatesStephen Colebournehttp://www.blogger.com/profile/01454237967846880639noreply@blogger.comBlogger5125tag:blogger.com,1999:blog-741750605858169835.post-26134755921662898182010-02-23T13:14:14.000+00:002010-02-23T13:14:14.000+00:00@Craig - Having one top level delegate per class p...@Craig - Having one top level delegate per class produces a one byte smaller steam at the expense of a much larger jar file.<br /><br />@Tom - I'm pretty sure that static nested classes are fine for serialization - its inner classes that aren't. I tested readObject/writeObject, and if all fields are transient, then it makes no difference to the stream.<br /><br />@Yardena, having an abstract superclass makes matters worse as there are now object header for Ser, MoneySer and BigMoneySer. Plus there isn't anything of value to share. Sometimes, OO isn't the right solution.Stephen Colebournenoreply@blogger.comtag:blogger.com,1999:blog-741750605858169835.post-8177897202818776472010-02-23T10:19:46.000+00:002010-02-23T10:19:46.000+00:00Hi Stephen,
I like your basic idea, it's simi...Hi Stephen,<br /><br />I like your basic idea, it's similar to Josh Bloch's "serialization proxy". However, from the perspective of object-oriented design, a single Ser class with a switch doesn't look appealing to me. I'd prefer Ser as base class for MoneySer and BigMoneySer, which may or may not be nested in Money and BigMoney respectively. I don't see why nested class would be discouraged by serialization spec - Josh Bloch uses them in his pattern, and he is proficient in JVM internals.<br /><br /> Yardena.Yardenahttp://sensualjava.blogspot.comnoreply@blogger.comtag:blogger.com,1999:blog-741750605858169835.post-88660916806211542842010-02-21T23:21:02.000+00:002010-02-21T23:21:02.000+00:00Nice to see serialisation format being looked at, ...Nice to see serialisation format being looked at, rather than slapping on `implements Serializable` in a base class and forgetting.<br /><br />Other common JDK (and JSR) classes don't do this sort of optimisation, so I wonder if it is worth it. Also note that adding classes and reflection artifacts will up the per-process overhead (although there may be benefits through lazy loading and the like).<br /><br />API serial format documentation may be difficult. Even non-public/protected classes have public serial format, and obvious needs to be specified by the JSR (including the integer constants).<br /><br />Default access instances of Externalisable implementations can have their readExternal/writeExternal methods called. Deserialisation generally allows creating such instances, although the forward process of serialisation shouldn't expose internal instances. It doesn't look like there is a particular problem with that in this case.<br /><br />The serialisation spec (section 1.10) says that serialisable inner classes are strongly discouraged. I think this should apply to nested classes as well. http://java.sun.com/javase/6/docs/platform/serialization/spec/serial-arch.html#4539<br /><br />readObject/writeObject and required (section 3.4) to call either defaultReadObject/defaultWriteObject or readFields/putFields. OTOH, many JDK classes do not do this. http://java.sun.com/javase/6/docs/platform/serialization/spec/input.html#2971Tom Hawtinhttp://blogs.sun.com/tackline/noreply@blogger.comtag:blogger.com,1999:blog-741750605858169835.post-79955084362464287652010-02-21T21:05:47.000+00:002010-02-21T21:05:47.000+00:00A typo in the last example: The assignment to fiel...A typo in the last example: The assignment to field "type" is missing in class "Ser".<br /><br />Shouldn't be "type" be native?<br /><br />What about object creation count during serialization? Have you done any performance analysis?Peter Jodeleithttp://www.e-spirit.comnoreply@blogger.comtag:blogger.com,1999:blog-741750605858169835.post-48888716801053442332010-02-21T16:50:03.000+00:002010-02-21T16:50:03.000+00:00I think that if you drop the byte field Ser#type, ...I think that if you drop the byte field Ser#type, and instead have one top level serialization delegate per class, then the size of the serialized data would be smaller on average.Craignoreply@blogger.com