views:

90

answers:

3

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

http://stackoverflow.com/questions/298733/java-util-list-is-an-interface-and-jaxb-cant-handle-interfaces

stacker
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
+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
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
The tutorial itself uses a List<T> so it seems to be working. Therefore the /must have standard constructor/ is fair tradeoff.
mbx
A: 

A couple of related thread can be found here and here.

Adeel Ansari