I am creating simple web services using jersey.
Here all are working but i'm not able get data as xml format now i am using json format for display data for this json display i added jersey-media-moxy dependency, i don't know i need to add any xml dependency.
This is my pom.xml
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.glassfish.jersey</groupId>
<artifactId>jersey-bom</artifactId>
<version>${jersey.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-servlet-core</artifactId>
<!-- use the following artifactId if you don't need servlet 2.x compatibility -->
<!-- artifactId>jersey-container-servlet</artifactId -->
</dependency>
<!-- uncomment this to get JSON support -->
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-moxy</artifactId>
</dependency>
<dependency>
<groupId>net.vz.mongodb.jackson</groupId>
<artifactId>mongo-jackson-mapper</artifactId>
<version>1.4.2</version>
</dependency>
</dependencies>
This is my resouce
@Path("student")
public class StudentResource {
private static Map<Integer, Students> stud_data = new HashMap<Integer, Students>();
static{
for(int i = 0; i < 10; i++){
Students stu = new Students();
int id = i+1;
stu.setId(id);
stu.setName("My Student "+id);
stu.setAge(new Random().nextInt(15)+1);
stud_data.put(id, stu);
}
}
@GET
@Produces(MediaType.APPLICATION_JSON)
public List<Students> getall(){
return new ArrayList<Students>(stud_data.values());
}
}
Please help me, how can i display the xml data like json.
Thanks in advance