After I add “extends java.io.Serializable” and a default constructor, the Person object will serialize as XML! Now if I could only figure out why my object won’t… I’ve tried just about everything.
It looks like Scala noticed that my object contained only the default values and decided not to record any of its vars. If I simply call incTesting() once so that it doesn’t have only default values, the object is written in XML with its members. I thought I had tested that, but apparently not. Thanks for the example Person that convinced me that it should work.
It looks like one problem is that the object I am really trying to serialize includes a scala.collection.mutable.TreeMap. If I try to serialize a plain old TreeMap with none of my own stuff, e.g.,
val map = new TreeMap[String, Double]()
map.put("me", 5)
new XMLEncoder(new BufferedOutputStream(new FileOutputStream("map.xml"))).writeObject(map)