<p>What's the simplest-to-use techonlogy available to save an arbitrary Java object graph as an XML file (and to be able to rehydrate the objects later)?</p>

[{'answer_id': 62675, 'author': 'Sietse', 'author_id': 6400, 'author_profile': 'https://Stackoverflow.com/users/6400', 'pm_score': 2, 'selected': False, 'text': '<p>Apache digester is fairly easy: <a href="http://commons.apache.org/digester/" rel="nofollow noreferrer">http://commons.apache.org/digester/</a><br>\nJAXB is newer and comes with annotation goodness: <a href="https://jaxb.dev.java.net" rel="nofollow noreferrer">https://jaxb.dev.java.net</a></p>\n'}, {'answer_id': 62711, 'author': 'Anarchofascist', 'author_id': 6740, 'author_profile': 'https://Stackoverflow.com/users/6740', 'pm_score': 0, 'selected': False, 'text': '<p><a href="http://java.sun.com/j2se/1.4.2/docs/api/java/beans/XMLEncoder.html" rel="nofollow noreferrer">java.beans.XMLEncoder</a> perhaps?</p>\n'}, {'answer_id': 62722, 'author': 'Steve Burton', 'author_id': 7127, 'author_profile': 'https://Stackoverflow.com/users/7127', 'pm_score': 1, 'selected': False, 'text': '<p>XStream is very simple <a href="http://x-stream.github.io/" rel="nofollow noreferrer">http://x-stream.github.io/</a></p>\n\n<p>XStream is a simple library to serialize objects to XML and back again.</p>\n'}, {'answer_id': 62745, 'author': 'Torsten Uhlmann', 'author_id': 7143, 'author_profile': 'https://Stackoverflow.com/users/7143', 'pm_score': 4, 'selected': True, 'text': '<p>The easiest way here is to serialize the object graph.\nJava 1.4 has built in support for serialization as XML.</p>\n\n<p>A solution I have used successfully is XStream (<a href="http://x-stream.github.io/)-" rel="nofollow noreferrer">http://x-stream.github.io/)-</a> it\'s a small library that will easily allow you to serialize and deserialize to and from XML.</p>\n\n<p>The downside is you can only very limited define the resulting XML; which might not be neccessary in your case.</p>\n'}, {'answer_id': 62751, 'author': 'A_M', 'author_id': 7144, 'author_profile': 'https://Stackoverflow.com/users/7144', 'pm_score': 2, 'selected': False, 'text': '<p>The Simple API is, well, simple! It\'s really good. <a href="http://simple.sourceforge.net/" rel="nofollow noreferrer">http://simple.sourceforge.net/</a></p>\n\n<p>You can also use XStream: <a href="http://www.ibm.com/developerworks/library/x-xstream/index.html" rel="nofollow noreferrer">http://www.ibm.com/developerworks/library/x-xstream/index.html</a></p>\n'}, {'answer_id': 62766, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 2, 'selected': False, 'text': '<p>XStream by the folks at Thoughtworks has a simple API and even deals with things like duplicate and circular references.  It seems to be actively developed and is well documented.</p>\n\n<p><a href="http://x-stream.github.io/" rel="nofollow noreferrer">http://x-stream.github.io/</a></p>\n'}, {'answer_id': 62872, 'author': 'John Shields', 'author_id': 7286, 'author_profile': 'https://Stackoverflow.com/users/7286', 'pm_score': -1, 'selected': False, 'text': '<p>If you are really only interested in serializing your objects to a file and then deserializing them later, then you might check out YAML instead of XML. YAML is much easier to work with than XML and the output files are very human-readable (which may or may not be a requirement). Check out <a href="http://yaml.org/" rel="nofollow noreferrer">yaml.org</a> for more information. I\'ve used <a href="http://jyaml.sourceforge.net/" rel="nofollow noreferrer" title="JYAML">JYAML</a> successfully on a recent project.</p>\n'}, {'answer_id': 63184, 'author': 'pjesi', 'author_id': 1296737, 'author_profile': 'https://Stackoverflow.com/users/1296737', 'pm_score': 1, 'selected': False, 'text': '<p>If you need to control the structure of the XML, the XStream is a good choice. You can use annotations to define precisely the structure/mapping of the XML and your objects.</p>\n'}, {'answer_id': 63256, 'author': 'erickson', 'author_id': 3474, 'author_profile': 'https://Stackoverflow.com/users/3474', 'pm_score': 2, 'selected': False, 'text': "<p>Use <code>java.beans.XMLEncoder</code>. Its API is very simple (actually a little too simple; it'd be nice to wire it to a SAX ContentHandler), but it works on many graphs out of the box, and it's easy to create your own persistence delegate for any odd-ball classes you might encounter.</p>\n\n<ul>\n<li>The syntax used by XMLDecoder allows\nyou to invoke any method, instance\nor static, including constructors,\nso it's extremely flexible.</li>\n<li>Other encoders name\nelements and attributes after class\nand field names, so there's no fixed schema for the result. The XMLEncoder's\nXML follows a simple DTD and can\neasily be validated or transformed,\neven when you've never seen the\ntypes it uses.</li>\n<li>You can assign objects an\nidentifier, and reference them\nthroughout the graph.</li>\n<li>You can refer to constants defined\nin classes or interfaces.</li>\n</ul>\n\n<p>And, it's built into Java SE, so you don't need to ship an extra library.</p>\n"}, {'answer_id': 65817, 'author': 'Andrew Harmel-Law', 'author_id': 2455, 'author_profile': 'https://Stackoverflow.com/users/2455', 'pm_score': 2, 'selected': False, 'text': '<p><a href="http://jaxb.java.net/" rel="nofollow noreferrer">JAX-B</a> is part of the standard APIs and really easy to use.</p>\n'}, {'answer_id': 66342, 'author': 'Alan Krueger', 'author_id': 7708, 'author_profile': 'https://Stackoverflow.com/users/7708', 'pm_score': 1, 'selected': False, 'text': "<p>I'd second (or third) XStream.  It reads and writes XML without needing any special binding configuration or placing lots of extraneous syntax in the XML.</p>\n"}, {'answer_id': 69304, 'author': 'Kevin Day', 'author_id': 10973, 'author_profile': 'https://Stackoverflow.com/users/10973', 'pm_score': 2, 'selected': False, 'text': '<p>If you need control over the XML that gets generated, I recommend taking a look at Betwixt (<a href="http://commons.apache.org/betwixt/" rel="nofollow noreferrer">http://commons.apache.org/betwixt/</a>) - it adds a lot of functionality to Apache\'s digester (Digester is good for building object graphs from XML, but is not so good for generating them).</p>\n\n<p>If you really don\'t care about the XML that gets generated (just that it can be deserialized in the future), then the XMLEncoder/Decoder classes built into Java or good - as long as the objects you are serializing follow the JavaBean specification.  The biggest area I\'ve run into problems with the XMLEncoder/Decoder solution is if you have a bean that returns an immutable list for one of it\'s properties - the encoder doesn\'t handle that situation very well.</p>\n'}, {'answer_id': 130042, 'author': 'ng.', 'author_id': 21896, 'author_profile': 'https://Stackoverflow.com/users/21896', 'pm_score': 2, 'selected': False, 'text': '<h1><em>Simple</em></h1>\n\n<p>Although XStream and JAXB can serialize an some object graphs succssfully they can not handle very complex graphs. The most powerful solution for large complex graphs is <a href="http://simple.sourceforge.net/" rel="nofollow noreferrer"><em>Simple</em> XML Serialization</a>. It can handle any graph. Also, it’s fast and simple to use without any dependencies.</p>\n\n<p>To quote the <em>Simple</em> project page:</p>\n\n<blockquote>\n  <p>Simple is a high performance XML serialization and configuration framework for Java. Its goal is to provide an XML framework that enables rapid development of XML configuration and communication systems. This framework aids the development of XML systems with minimal effort and reduced errors. It offers full object serialization and deserialization, maintaining each reference encountered. In essence it is similar to C# XML serialization for the Java platform, but offers additional features for interception and manipulation. </p>\n</blockquote>\n'}, {'answer_id': 2337481, 'author': 'Karussell', 'author_id': 194609, 'author_profile': 'https://Stackoverflow.com/users/194609', 'pm_score': 1, 'selected': False, 'text': '<p>I <a href="http://karussell.wordpress.com/2009/09/03/xml-serializers-for-java/" rel="nofollow noreferrer">put together a list</a> with a lot of xml serialization libraries and its license</p>\n'}, {'answer_id': 51415454, 'author': 'Basil Bourque', 'author_id': 642706, 'author_profile': 'https://Stackoverflow.com/users/642706', 'pm_score': 0, 'selected': False, 'text': '<h1>Jackson</h1>\n\n<p>The <a href="https://github.com/FasterXML/jackson" rel="nofollow noreferrer"><em>Jackson Project</em></a> is a processing and binding library for XML, JSON, and some other formats.</p>\n\n<blockquote>\n  <p>… Jackson is a suite of data-processing tools for Java (and the JVM platform), including the flagship streaming JSON parser / generator library, matching data-binding library (POJOs to and from JSON) and additional data format modules to process data encoded in Avro, BSON, CBOR, CSV, Smile, (Java) Properties, Protobuf, XML or YAML; and even the large set of data format modules to support data types of widely used data types such as Guava, Joda, PCollections and many, many more… </p>\n</blockquote>\n'}]
['https://Stackoverflow.com/questions/62650', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/-1/']