Java Serialization Loops

In general, I appreciate the work the Java folks have done to make remote procedure calls easy. And to a large part, they have done a pretty good job. The single weakness that I can find is their misunderstanding of their own data structures.

For example, say I have two HashMaps in JDK 1.3.1. Each has a single key/value pair: a String "other" as the key and a HashMap (the other) as the value. It seems pretty obvious that if you're looking at the structure you'd see one, move to the other, and see the first again and stop. But Java isn't that smart. It creates an infinite loop trying to evalutate the HashMaps as opposed to seeing that they are in fact one in the same.

This means that to serialize the example structure I have to create four objects - two of each with the "other" link disabled in two of the four. Now, no matter where I am, I can "see" the relationship, but it's not circular.

This is a pain and there's no reason for it as the serialization would be able to identify the objects and provide placeholders for de-serialization. But that's life with Java...