I am new to using JAX-RS and have written an example application that outputs a json object. but I get an exception. Here is my code:
@Path("/hello") public class HelloWorldService { @GET @Path("/query/{artist_id}") @Produces("application/json") public Data getMsg(@PathParam("artist_id") int artist_id, @QueryParam("from") int from, @QueryParam("to") int to) { Data d=new Data(); d.setName("Mateen"); d.setRoll(77); return d; }
}
My data is just a POJO class:
@XmlRootElement public class Data { private int roll; private String name; public int getRoll() { return roll; } public void setRoll(int roll) { this.roll = roll; } public String getName() { return name; } public void setName(String name) { this.name = name; } }
I get an exception:
javax.ws.rs.WebApplicationException: com.sun.jersey.api.MessageException: A message body writer for Java class com.abc.data.Data, and Java type class com.abc.data.Data, and MIME media type application/json was not found
What am I doing wrong?
java rest jax-rs
user1730789 Oct 28 2018-12-12T00: 00Z
source share