[jdom-interest] Resend: Is there a JDOM 8 Document serialization problem?

Tom Preston tpreston at amadeusboston.com
Sat Apr 6 07:37:07 PST 2002

I sent this msg a while ago but got no reply.  Has anyone else reproduced
this problem?...simple steps below. Passing Document through serialization
killing the children of the root!


From: Tom Preston <tpreston at amadeusboston.com>
Content-Type: multipart/alternative;
Subject: [jdom-interest] MORE ABOUT: Problem with Jdom8 - getChildren() on
root ...
Date: Fri, 29 Mar 2002 12:12:51 -0500

There IS more to the story.  We are using EJB.  When we get rid of the EJB
aspect the problem goes away.  So, we find that the problem is returning a
jdom 8 Document from EJB.  Something in the marshalling process is messing
up the document so that root.hasChildren() returns true while
root.getChildren returns a zero sized list after ANY Document has been
returned from ANY EJB method.  Here is the trivial example for reproduction:
Make an EJB which has this signature in the RemoteInterface:
  public Document getSimpleDoc() throws Exception, RemoteException;
In the EJBean class implement the remote interface:
  public Document getSimpleDoc() throws Exception {
    Element theRoot = new Element("Root");
    Element levelA = new Element("A");
    Element levelB = new Element("B");
    levelB.addContent(new Element("levelB").addContent("5"));
    Document doc = new Document(theRoot);
Element root = doc.getRootElement();
System.out.println("Inside of the EJB Method: root.hasChildren(): " +
root.hasChildren() + " root.getChildren().size(): " +
root.getChildren().size() );
    return doc;

Now make a trivial JSP to call the EJB getSimpleDoc() method:
<%@ page import="
  Context ctx = Utils.getServerInitialContext();
  ProductDisplayHome productDisplayHome =
  ProductDisplay productDisplay = productDisplayHome.create();
  Document doc = productDisplay.getSimpleDoc();
Element root = doc.getRootElement();
out.print("Inside of the JSP (the Caller) Method: root.hasChildren(): " +
root.hasChildren() + " root.getChildren().size(): " +
root.getChildren().size() );
//  XMLOutputter xo = new XMLOutputter("  ", true);
//  xo.output(doc,System.out);

You will see that the System.out.println from WITHIN the EJB (before the
Document gets returned -- and therefore, before it gets marshalled and
unmarshalled) prints out:
   Inside of the EJB Method: root.hasChildren(): true
root.getChildren().size(): 1
But inside of the JSP when dealing with the Document that has gone thru
serialization (marshalling and unmarshalling) you get:
  Inside of the JSP (the Caller) Method: root.hasChildren(): true
root.getChildren().size(): 0 
For the very same Document...the only difference being that the Document was
passed thru EJB Marshalling and Unmarshalling, you have two different
getChildren() of root results.  
My theory is that something in JDOM version 8 RC has made some field
"transient" that shouldn't be and therefore the Document object is different
before serialization than it is after serialization.
I think that this is a major problem for anyone returning Document objects
from EJB methods (like we were).
Tom Preston


More information about the jdom-interest mailing list