What is the most appropriate way to serialize Java Classes to XML? I tried JAXB, but it has issues with Interfaces and Generics. What sollution is least intrusive but scalable?
A:
I would suggest to overcome the issues with interfaces and generics you have with JAXB.
http://stackoverflow.com/questions/826736/jaxb-marshalling-and-generics
stacker
2010-05-25 09:09:01
I already read those but find the sollutions wont fit, it does not scale to build Adapters for every Class using generics.Transformation to/from Arrays would be OK - if JAXB would do it transparently and without my help.
mbx
2010-05-26 12:31:14
+2
A:
I've always had positive experiences with XStream:
http://xstream.codehaus.org/tutorial.html#to-xml
As you can see, it's simple to use.
I haven't actually used XStream with Generics (I've only ever used it for simple JavaBean type classes), but Google seems to suggest it handles them without problems. e.g. http://techo-ecco.com/blog/xstream-spring-ws-oxm-and-generics/
amir75
2010-05-25 09:13:56
n.b. that blog link leads on to talk about using Spring to simplify the outputted xml, but the first xml snippet indicates that plain-old XStream handles the Generic LinkedList nicely
amir75
2010-05-25 09:17:15
The tutorial itself uses a List<T> so it seems to be working. Therefore the /must have standard constructor/ is fair tradeoff.
mbx
2010-05-26 12:43:25