package com.marketplace.acres.dummyapp.test;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.xml.bind.annotation.XmlRootElement;
@Path("/fortest")
@XmlRootElement
public class ForTest {
public int id;
public String name;
public ForTest( ){
}
public ForTest(int id, String name){
this.id = id;
this.name = name;
}
@GET
@Produces(MediaType.APPLICATION_XML)
public ForTest getMessages(){
ForTest emp1 = new ForTest(22,"sachin");
return emp1;
}
}
this code gives out the expected XML output:
<forTest>
<id>22</id>
<name>sachin</name>
</forTest>
But when I try to get the data in json format by changing:
@Produces(MediaType.APPLICATION_XML) to @Produces(MediaType.APPLICATION_JSON), I get an error:
SEVERE: MessageBodyWriter not found for media type=application/json, type=class com.marketplace.acres.dummyapp.test.ForTest, genericType=class com.marketplace.acres.dummyapp.test.ForTest.
How to get the data in JSON format?