Since the objects that I'm representing in Java are actual XML objects, would it be appropriate to serialize them to XML?
I assume you mean something like a DOM. And that you then serialize using some XML binding ... treating the DOM objects as POJOs !!
Bad idea, IMO.
If not, why would this be a bad idea (aside from performance reasons)?
- Serialization and deserialization performance will be bad.
- The serialized form will be bloated.
- The generated XML will be unreadable.
- The serialization will difficult for anything else to process. Consider trying an XSLT transformation on it. Consider trying to process it using an event-based parser.
Actually, I'm struggling to think of any reason that this might be a good idea.
UPDATE
Your explanation (in your updates / comments) as to why doing this are unconvincing:
It's often appropriate to consider a custom serialized form when an object's logical implementation is largely different than its physical implementation (from Bloch's Effective Java, item 75).
Bloch's advice is to consider using a custom representation. And implicit in that is the assumption that you consider a BETTER custom representation than the standard one you have in front of you.
In my case, the physical form will differ significantly from the logical form and a custom serial representation is appropriate.
That doesn't explain why you want to represent the DOM in XML in the first place. Or why you think it is better.
Since the object will ALWAYS be able to be represented by XML, it seems like a good fit logically, ...
You haven't explained that logic.
... but I'm trying to understand the implications of this with the Java language (I.E. performance).
Well the implications are as I explained above. And there is nothing Java specific about this.
OK lets look at this from another perspective.
- You have some information.
- You represent that information in XML.
- You parse the XML to give you an in-memory representation - a DOM.
- You apply something like jaxb to give you an XML representation of the DOM ... viewed as POJOS
- You serialize the DOM.
What you end up with an XML representation of Java objects that represent some XML that represents your original information.
How is this better than your XML representation of the original information?
Now, maybe, if at step 3 you had used jaxb and deserialized to custom Java classes ... then serializing those Java classes to would make sense. But then you don't have "Java objects that represent XML elements". Rather you have Java objects that represent the information that was represented by your original XML.
That is a COMPLETELY DIFFERENT THING to what you actually wrote in your Question. And if that is what you meant, it explains why people didn't understand you ... and thought what you were actually saying made little / no sense.