I wrote a Rest webservice in jersey. when I return from get method to client, client recieved a HTTP ERROR: 500 response if i return String Object from MyMessage class it is fine. service Class is:
@Path("msg")
public class MyMessage {
@GET
@Produces(MediaType.APPLICATION_JSON)
public MyObject getMessage() {
MyObject object = new MyObject();
object.setId(1);
object.setMessage("sdsadsadsadsa");
return object;
}
}
and class object that return from service is MyObject that wrapped message:
public class MyObject {
private String message;
private int id;
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
}
I use embedded jetty server and this is pom.xml :
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<jersey.version>2.25</jersey.version>
<jetty.version>9.2.10.v20150310</jetty.version>
</properties>
<dependencies>
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-jetty-http</artifactId>
<version>${jersey.version}</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.core</groupId>
<artifactId>jersey-server</artifactId>
<version>${jersey.version}</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-servlet-core</artifactId>
<version>${jersey.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-servlet</artifactId>
<version>${jetty.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-server</artifactId>
<version>${jetty.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-util</artifactId>
<version>${jetty.version}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.jaxrs</groupId>
<artifactId>jackson-jaxrs-json-provider</artifactId>
<version>2.3.3</version>
</dependency>
</dependencies>
Response
but never use it. But this not the reason why you get status code500
. Please edit your question and provide a stacktrace and information about the libraries that you use. – braunpet