Not sure what I have done wrong. I have my data model
Waypoint.java:
@XmlRootElement
public class Waypoint {
@XmlElement
private String test;
public String getTest() {
return test;
}
public void setTest(String test) {
this.test = test;
}
}
then in my waypoint service i have my post function: WaypointService.java
@POST
@Path("/waypoint")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Waypoint addState(Waypoint waypoint) throws Exception {
try {
return waypoint;
} catch (Exception e) {
logger.log(Level.SEVERE, null, e);
}
}
When i try to make the post call from postman I receive a 415 error: [Postman Post request] https://i.stack.imgur.com/1IM6u.png
Content-Type: application/json
Accept: application/json
Also here are the main dependencies i have installed:
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-json-jackson</artifactId>
<version>3.04</version>
</dependency>
<dependency>
<groupId>org.glashfish.jersey.media</groupId>
<artifactId>jersey-media-moxy</artifactId>
<version>3.04</version>
</dependency>
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-server</artifactId>
<version>3.04</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
<type>jar</type>
</dependency>
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-servlet</artifactId>
<version>1.19</version>
</dependency>
Any help with this issue would be nice, I've been stuck on this issue for some time and look up a lot of videos/forum help and still havent been able to find out the problem. Just to clarify! I have a post request sending in json data in the body, and I just want it to recieve the data and output it back (just for testing purposes).
CodePudding user response:
The Waypoint.java produces an xml and @Path("/waypoint") seems to consume a JSON as well as produce a JSON. I think thats why you are getting unsupported media type error