I am trying to send a JSON object through a JAX-RS web service.
My file web.xml is:
<servlet>
<description>JAX-RS Tools Generated - Do not modify</description>
<servlet-name>JAX-RS Servlet</servlet-name>
<servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>jersey.config.server.provider.packages</param-name>
<param-value>it.notifire</param-value>
</init-param>
<init-param>
<param-name>com.sun.jersey.api.json.POJOMappingFeature</param-name>
<param-value>true</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>JAX-RS Servlet</servlet-name>
<url-pattern>/jaxrs/*</url-pattern>
</servlet-mapping>
The class that models the object I want to send is:
public class GPSCoordinate {
private float latitudine;
private float longitudine;
public float getLatitudine() {
return latitudine;
}
public void setLatitudine(float latitudine) {
this.latitudine = latitudine;
}
public float getLongitudine() {
return longitudine;
}
public void setLongitudine(float longitudine) {
this.longitudine = longitudine;
}
}
The root class resource is:
@Path("position")
public class Position {
@Context
private UriInfo context;
@GET
@Produces(MediaType.APPLICATION_JSON)
public GPSCoordinate getHTML() {
GPSCoordinate coord = new GPSCoordinate();
coord.setLatitudine(90.45f);
coord.setLongitudine(34.56f);
return coord;
}
}
Now, when i try to access the service I point my browser to the following link
http://localhost:8080/Notifire/jaxrs/position
and i get the following error:
message org.glassfish.jersey.message.internal.MessageBodyProviderNotFoundException: MessageBodyWriter not found for media type=application/json
In my WEB-INF/lib folder I have the last release of jersey JAX-RS implementation (jaxrs-ri-2.5.jar) and the jersey-json.jar archive.
Any help would be much appreciated.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…