One of the best alternatives is to use the pure Java XStream library.
This works with case classes out of the box, with some tweaking - I use the XStreamConversions class from mixedbits-webframework - it also works with list, tuple, symbol, ListBuffer and ArrayBuffer. So this is not ideal, but you can fine-tune it to your specific needs.
Here is a small example.
import com.thoughtworks.xstream.XStream import com.thoughtworks.xstream.io.xml.StaxDriver import net.mixedbits.tools.XStreamConversions case class Bar(a:String) case class Foo(a:String,b:Int,bar:Seq[Bar]) object XStreamDemo { def main(args: Array[String]) { val xstream = XStreamConversions(new XStream(new StaxDriver())) xstream.alias("foo", classOf[Foo]) xstream.alias("bar", classOf[Bar]) val f0 = Foo("foo", 1, List(Bar("bar1"),Bar("bar2"))) val xml = xstream.toXML(f0) println(xml) val f1 = xstream.fromXML(xml) println(f1) println(f1 == f0) } }
This leads to the following conclusion:
<?xml version="1.0" ?><foo><a>foo</a><b>1</b><bar class="list"><bar><a>bar1</a></bar><bar><a>bar2</a></bar></bar></foo> Foo(foo,1,List(Bar(bar1), Bar(bar2))) true
For Java 1.6 / Scala 2.9, the dependencies are the xstream.jar file and the XStreamConversions class mentioned.
source share