Modern alternative to Java XStream library?
In order of preference, relevancy and activity:
JAXB
Visit the JAXB project's site to check out the tutorial and guide. Have also a look at the original JAXB architecture whitepaper.
The JAXB projet listed above is the reference implementation of the API, and is packaged in by the GlassFish Application Server.
EclipseLink's MOXy
Visit the EclipseLink project's site and read this introductory article to EclipseLink on InfoQ, and see Blaise Doughan's answer about MOXy.
EclipseLink originated from Oracle's TopLink and is now open source, managed by the Eclipse Foundation, and used in a number of Eclipse-based products.
XStream
Yes, XStream, because it's actually been updated in 2011 with a major update and 2 service releases since you asked, so it seems well-maintained and a pretty good contender used by mature projects. Don't forget to check what's new in version 1.4.x.
Visit the XStream project's site and its tutorial to compare.
XmlBeans
Visit the XmlBeans project's site.
XmlBeans is a well-tested project that has been around for a while.
JiBX
Visit the JiBX project's site, follow the tutorial and guide.
JiBX might be a simpler alternative if you don't like the complexity of XmlBeans or even JAXB.
The fact that something hasn't been updated for 3 years doesn't mean that it is out of date. It might simply mean that there has been no need to update it. If there is no need to change a project, why change it?
Another explanation for the apparent lack of "progress" is that changing library APIs tends to be disruptive to projects that depend on them. This is particularly problematic for projects that combine lots of third-party components and libraries into one Java application.
Looking for alternatives to a library is a good thing, but simply doing this because the library hasn't been updated recently is not. If XStream does what you need, stick with it. Newer doesn't necessarily mean better.
UPDATE - 2019
XStream has been receiving updates with a new release at least once a year since 2011. Refer to the Changes page for details, and look at the activity on the Github repository for the project. As of now, the theory that XStream is not being maintained is (IMO) thoroughly debunked.
Note: I'm the EclipseLink JAXB (MOXy) lead, and a member of the JAXB (JSR-222) expert group.
You are correct in considering a libraries release frequency when making a software choice. There are many reasons for a new product release:
- Customer Requests - No matter how good your library is, your user base will have improvement suggestions and feature requests.
- Industry Developments - Modular deployment is hot topic right now, over the past few years changes had to be made to EclipseLink to make it compatible with OSGi.
- New Java Versions - Java SE 7 will be released soon, while this does not necessitate a release we did need to make some tweaks in our upcoming release to ensure we were compatible. Also over time more features will be added to leverage new Java aspects (EclipseLink requires a minimum of Java SE 5).
Another important aspect of evaluating any open source project is the number of active committers. Sites like ohloh.net are useful for that:
- http://www.ohloh.net/p/3459
JAXB (JSR-222)
JAXB is more than an implementation, it is a standard that is developed through the Java Community Process (JCP). There have been participants from such object-to-XML libraries as XML Beans (BEA), EMF (IBM), TopLink (Oracle), etc. Because JAXB is part of Java EE it is available in every application server: WebLogic, GlassFish, WebSphere, JBoss, etc.
JAXB Offers:
- 100% schema coverage
- Multiple implementations: Metro, EclipseLink MOXy, Apache JaxMe, etc
- Included in Java SE 6, compatible with JDK 1.5
- Ability to start from XML schema or Java classes
- Various extension mechanisms including XmlAdapter - Example
- Option to preserve XML infoset via Binder - Example
- Binding layer for JAX-WS (Web Services)
- Binding layer for JAX-RS (Rest) - Example
- Compatible with JSON (when used with libraries such as Jettison) - Example
EclipseLink JAXB (MOXy)
MOXy is a JAXB implementation that offers many useful extensions, including:
True Object to XML Mapping by Leveraging XPath
XPath based mapping allows you to start with both Java classes and an XML schema and map the two together.
- http://bdoughan.blogspot.com/2010/09/xpath-based-mapping-geocode-example.html
- http://bdoughan.blogspot.com/2011/03/map-to-element-based-on-attribute-value.html
Mapping File for Handling 3rd Party Classes
In the current JAXB spec the metadata is supplied via annotations. This can be problematic to use with 3rd party classes that cannot be modified. This is why MOXy offers a way to specify the mappings via XML:
- http://bdoughan.blogspot.com/2010/12/extending-jaxb-representing-annotations.html
- http://bdoughan.blogspot.com/2011/04/moxys-xml-metadata-in-jax-rs-service.html
Extensions for Mapping JPA Entities
Often times you need to do more with your Java objects then just map then to XML. You may also need to persist them to a database. This means your object model may have additional constraints on it that you need to account for. MOXy offers a number of extensions for this kind of use case:
- http://bdoughan.blogspot.com/2010/07/jpa-entities-to-xml-bidirectional.html
- http://wiki.eclipse.org/EclipseLink/Examples/MOXy/JPA
Comparisons
Below are a couple comparisons I have done comparing JAXB to XStream and Simple:
- http://bdoughan.blogspot.com/2010/10/how-does-jaxb-compare-to-xstream.html
- http://bdoughan.blogspot.com/2010/10/how-does-jaxb-compare-to-simple.html