[jdom-interest] Problems with JDOM Beta 8 RC1

Theo Harper Theo_Harper at systemsunion.com
Fri Mar 15 09:29:59 PST 2002


Hi,

I am having a problem serializing org.jdom.Element with the latest release,
if you try the following code the size returned from the deserialised
element is incorrect.  This problem did not occur with Beta 7.

import org.jdom.input.SAXBuilder;
import org.jdom.Document;
import org.jdom.Element;
import org.jdom.JDOMException;

import java.io.*;
import java.util.List;

public class Test {

    public static void main(String[] args) {

        try {
            SAXBuilder builder = new SAXBuilder();

            Document document = builder.build(new
StringReader("<root><child></child></root>"));

            Element root = document.getRootElement();

            File f = File.createTempFile("tmp", "tmp");

            List children = root.getChildren("child");

            System.out.println("Constructed size=" + children.size());
            System.out.println("Constructed element=" +
((Element)children.get(0)).getName());

            ObjectOutputStream objectOutputStream = new
ObjectOutputStream(new FileOutputStream(f));
            objectOutputStream.writeObject(root);
            objectOutputStream.close();

            ObjectInputStream objectInputStream = new ObjectInputStream(new
FileInputStream(f));
            Element readRoot = (Element)objectInputStream.readObject();
            objectInputStream.close();

            children = readRoot.getChildren("child");
            System.out.println("Serialized size=" + children.size());
            System.out.println("Serialized element=" +
((Element)children.get(0)).getName());

        } catch (Exception e) {
            e.printStackTrace();
        }

    }
}

Thanks,
Theo



More information about the jdom-interest mailing list