I'm having problems with the post requests in an API restful i'm testing and I don't see where is the error.
Here I've the API
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import test.api.models.Test;
import test.api.MediaType;
@Path("/test")
public class testResource {
@GET
public String getSomething(){
return "Ok GET";
}
@POST
@Consumes(MediaType.TEST)
public String postSomething(Test test){
System.out.println("Got: " + test);
return "Ok POST";
}
}
The problem is that when I do a get request to localhost:8080/test-api/test from postman application, I get "Ok GET". But If I do a post request I get 500 server error. I'm setting correctly the content-type header field. The error I get is:
"message": "HTTP 500 Internal Server Error",
"status": 500
and this is how I'm sending the data:
{
"a": "one",
"b": "two"
}
I think the problem can be in the Test class, because if I change the input parameter of the postSomething method to a String type I get the "Ok POST".
Here is the test class where I don't see anything strange...
public class Test {
public String a;
public String b;
public Test ( String a, String b){
this.a = a;
this.b = b;
}
public String getA() {
return a;
}
public void setA(String a) {
this.a = a;
}
public String getB() {
return b;
}
public void setB(String b) {
this.b = b;
}
}
Anyone see something strange?
Thank you.