bpsm / edn-java

a reader for extensible data notation
Eclipse Public License 1.0
100 stars 24 forks source link

issue43: Make parsed EDN values Serializable #44

Closed bpsm closed 8 years ago

bpsm commented 8 years ago

For some use cases it is desirable that the Values produced by parsing EDN text be able to participate in Java Serialization.

This branch teaches Keyword, Symbol, Tag, TaggedValue and DelegatingList to be Serializable.

The case of Keyword is complicated by the fact that Keyword instances are controlled. We use a SerializationProxy which implements readResolve() by calling newKeyword() so as to maintain the invariant:

Symbol s1 = ..., s2 = ...;
Keyword kw1 = Keyword.newKeyword(s1);
Keyword kw2 = Keyword.newKeyword(s2);

(s1.equals(s2)) == (kw1 == kw2)

That is, any two keywords are identical if and only if they were created from any two equal Symbols.

Note that newKeyword(prefix, name) is exactly equivalent to newKeyword(newSymbol(prefix, name)).