Ok, so I am building a RESTful service in Java using Jersey.
I have implemented the POST which works wonderfully, which creates a new row in the Category table in my Database. Now when I try to do the DELETE, I pass it the same row in JSON, but it returns a "400: Bad Request - the request cannot be fulfilled due to bad syntax"
.
I am confused, since the JSON is copied and pasted from the result I get when I do a GET on that specific category.
Here is the relevant code:
@Path("/categories/")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
public class CategoryResource {
@POST
public Response addCategory(Category category, @Context UriInfo uriInfo)
{
JSONArray json_array = category_service.addCategory(category);
URI uri = uriInfo.getAbsolutePathBuilder().path(category.getCategory_name()).build();
return Response.created(uri)
.status(Status.CREATED)
.entity(json_array.toString())
.build();
}
@DELETE
public Response deleteCategory(Category category)
{
System.out.println("Category = " + category.toString());
category_service.deleteCategory(category);
return Response.ok().build();
}
The system.out.println() is never executed because it seems like it fails to do the encoding of the category. The Category class is here, replete with the usual getters and setters:
@XmlRootElement
public class Category {
private int category_id;
private String category_name;
private boolean child;
private int parent_id;
private boolean category_state;
private String category_reason;
public Category() {
}
The JSON that is being passed in the raw looks like this:
{
"category_id": 1,
"category_name": "tennis",
"child": true,
"parent_id": 4,
"category_state": true,
"category_reason": "I Like Tennis"
}
Note that this has been copied and pasted from the result of the GET....