7

What is the most appropriate way to serialize Java Classes to XML? I tried JAXB, but it has issues with Interfaces and Generics. What solution is least intrusive but scalable?

mbx
  • 6,292
  • 6
  • 58
  • 91

2 Answers2

4

I've always had positive experiences with XStream:

http://x-stream.github.io/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/

facundofarias
  • 2,973
  • 28
  • 27
laher
  • 8,860
  • 3
  • 29
  • 39
  • 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 – laher May 25 '10 at 09:17
  • The tutorial itself uses a List so it seems to be working. Therefore the /must have standard constructor/ is fair tradeoff. – mbx May 26 '10 at 12:43
1

I would suggest to overcome the issues with interfaces and generics you have with JAXB.

JAXB Marshalling and Generics

java.util.List is an interface, and JAXB can't handle interfaces

Community
  • 1
  • 1
stacker
  • 68,052
  • 28
  • 140
  • 210
  • 1
    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 May 26 '10 at 12:31