Show Topics
Hide Topics

JAX-RS XML Example Using Jersey

JAX-RS supports conversion of java objects into XML with the help of JAXB. As Jersey it self contains JAXB libraries we no need to worry about JAXB-Jersey integration. Just include “jersey-server.jar”

 

 

1.Create Dynamic web project in eclipse, convert that into Maven Project

 

2.Configure pom.xml

 

 

 

3.Configure web.xml

 

 

4.write Customer POJO class

Write Customer POJO class & Annotate object with JAXB annotation, for conversion later.

 

 

5.Create RESTFul webservice

To return a XML file, annotate the method with @Produces(MediaType.APPLICATION_XML). Jersey will convert the JAXB annotated object into XML file automatically.

 

 

6.Test Webservice directly by using URL / writing webservice client

http://localhost:8080/JAXRS-XML-Jersey-Example/rest/customers/78878

 

Download Example Code