I’m implementing a small RESTful web service, and figured I’d return XML blobs to represent the resources, which map fairly directly to some Java classes I have.
I could do custom XML encoders for each class, but I stumbled across JAXB (which I have never used), and it seemed like a clean way of avoiding having to write tedious encoding logic that I’d have to keep in synch if I add new properties to any of the classes.
So, my question is: is JAXB too heavyweight for something as simple as this? Is it worth using as just something to map a basic structure, collection of beans, etc. to an XML document?
edit: I’m using Jersey to build the service.
Note: I’m the EclipseLink JAXB (MOXy) lead, and a member of the JAXB (JSR-222) expert group.
If you are using a JAX-RS implementation (Jersey, RESTeasy, Wink, etc) to create your RESTful service then JAXB is the default binding layer and integrates seamlessly:
For an example see: