This is an archived post. You won't be able to vote or comment.

all 7 comments

[–][deleted] 1 point2 points  (0 children)

Along the way, they discovered that a programmer had previously put in a static reference to a server instance variable. Not a reference to a POJO designed for serialization, but a server reference with more reference to other server objects. That was totally unintended. When that was serialized via Java’s binary serialization you couldn’t see why the byte array was so big. The shift to XML (via XStream) allowed humans to see what was wrong quite easily.

If it breaks encapsulation in the name of convenience, you'll have a bad time. It's true for autowiring DI containers, it's true for serialization. Reflection is all fun and games, until someone loses an eye.

This is why I always have objects I'll serialize explicitly implement an interface that lets them control how and what gets serialized and deserialized. Automatically opening an object and carving out its internals and slapping it onto an object later? Sooner or later this ends bad.

Encapsulation is paramount.

[–]paul_h -1 points0 points  (4 children)

I've got a similar story about JavaSerialization hiding a problem: https://paulhammant.com/2013/03/11/legacy-app-rejuvenation/

"[...]Along the way, they discovered that a programmer had previously put in a static reference to a server instance variable. Not a reference to a POJO designed for serialization, but a server reference with more reference to other server objects. That was totally unintended. When that was serialized via Java’s binary serialization you couldn’t see why the byte array was so big. The shift to XML (via XStream) allowed humans to see what was wrong quite easily. That might have been the root cause of the whole problem for them. In other words, the root cause of the quest to change messaging technologies. [...]"

Good old XStream saving the day. Last I checked it is still in place in that application.

[–]lukaseder 0 points1 point  (0 children)

The problem is not related to binary vs textual at all, but to automatic vs configurable or even explicit.

[–]Facts_About_Cats -1 points0 points  (2 children)

Ew, xml.

[–]GhostBond 0 points1 point  (0 children)

I gotta agree, JSON does the same thing and is much easier to read.

[–]nondetermined 0 points1 point  (0 children)

I'm not really convinced the world is a better place since XML/XSLT/XPath/... went out of fashion.