Consider following Rest Interface. We define Annotation "Produces" which can generate different format type output. In your case APPLICATION_JSON will generate JSON and APPLICATION_XML will generate XML format. So decide accordingly.
package : javax.ws.rs.PathParam; @GET @Path("/helloRest") @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) public MyPojo getHello();
You can control how XML format is generated using Annotation from package javax.xml.bind.annotation. This will help you to control your POJO objects names and other validations if needed
@XmlRootElement(name="MyHello") @XmlAccessorType(XmlAccessType.FIELD) public class MyPojo { @XmlElement(name="id") private int id; @NotNull @Size(min = 1, max = 10, message = "Mandatory Field") @FormParam("code") private String code; @NotNull @Size(min = 1, max = 50, message = "Mandatory Field") @FormParam("name") private String name; @FormParam("status") private String status; JSON Format: {"id":48,"code":"dfgfdgd","name":"aaaaaaaaa","status":"dfgfdgdd"} XML Format: <?xml version="1.0" encoding="UTF-8" standalone="yes"?> <MyHello><id>168</id> <code>AS3</code> <name>gfhfgh</name> <status>A</status> </MyHello>