Reputation: 147
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?
Upvotes: 0
Views: 55
Reputation: 147
solved by uncommenting these lines in pom.xml
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-moxy</artifactId>
</dependency>
But I was initially confused with EffectivePOM.xml and pom.xml in Eclipse what is the difference between the two ?. In effective POM this was already uncommented.
Upvotes: 0