Search code examples
jaxbjerseyxstream

JAXB or Xstream on a Jersey Restful application


I want to know which solution is better for a Jersey Rest Web service. In some cases JAXB is not able to handle some types. Is it better to use XStream?


Solution

  • Depends on your use case - if you think JAXB will be significant limitation, you can use XStream. Btw Jersey recently added support for MOXy, which could help you overcome some corner cases in JAXB Reference impl in JDK.

    Pro JAXB

    • out of the box functionality with Jersey
    • ability to specify own JAXBContext
    • stable; lots of tests / support from Jersey/JAXB team

    Con JAXB

    • it doesn't work as expected for some corner cases (java/xml binding has limitations due to different nature of these languages)

    Pro XStream:

    • you probably have some experience with that

    Con XStream:

    • you'll need implement support for it (MessageBodyReaders/Writers) in Jersey