views:

5134

answers:

8

Is there a (preferably free) Java analogue of .NET's XML serialization?

A: 

If you're talking about automatic XML serialization of objects, check out Castor:

Castor is an Open Source data binding framework for Java[tm]. It's the shortest path between Java objects, XML documents and relational tables. Castor provides Java-to-XML binding, Java-to-SQL persistence, and more.

Theo
+14  A: 

XStream is pretty good at serializing object to XML without much configuration and money! (it's under BSD license).

We used it in one of our project to replace the plain old java-serialization and it worked almost out of the box.

Barak Schiller
Very useful, it can have problems on complecated tree structures such as JGraph with non string node objects though.
mikek3332002
Simpler and better then other solutions
daitangio
+13  A: 

The "Official" Java API for this is now JAXB - Java API for XML Binding. The reference implementation lives at https://jaxb.dev.java.net/

Cheekysoft
That's right, JAXB is definitely the best option!
ivan_ivanovich_ivanoff
A: 

XMLBeans works great if you have a schema for your XML. It creates Java objects for the schema and creates easy to use parse methods.

John Meagher
A: 

Usually I use jaxb or XMLBeans if I need to create objects serializable to XML. Now, I can see that XStream might be very useful as it's nonintrusive and has really simple api. I'll play with it soon and probably use it. The only drawback I noticed is that I can't create object's id on my own for cross referencing.

@Barak Schiller
Thanks for posting link to XStream!

bibix
+4  A: 

You may want to look at Simple, its the closest thing I've found to the System.Xml.Serialization in .Net.

ARKBAN
A: 

Don't forget JiBX.

Cheeso