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.
JAXB stands for Java Architecture for XML Binding. It provides mechanism to marshal (write) java objects into XML and unmarshal (read) XML into object. Simply, you can say it is used to convert java object into xml and vice-versa.
JAXB simplifies access to an XML document from a Java program by presenting the XML document to the program in a Java format. The first step in this process is to bind the schema for the XML document into a set of Java classes that represents the schema.
Marshalling is the process of transforming Java objects into XML documents. Unmarshalling is the process of reading XML documents into Java objects. The JAXBContext class provides the client's entry point to the JAXB API. It provides API for marshalling, unmarshalling and validating.
The JAXBContext class provides the client's entry point to the JAXB API. It provides an abstraction for managing the XML/Java binding information necessary to implement the JAXB binding framework operations: unmarshal, marshal and validate.
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:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With