-1

Currently my rest resources look like this:

 @GET
 @Override
 @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
 public List<Customer> findAll() {
    return super.findAll();
 }

From the looks of it, I feel like

curl -v -H "Accept:application/json" -H "Accept-encoding:gzip" http://localhost:8080/mavenproject1/webresources/com.mycom.mavenproject1.customer

should get me a response in JSON but, I get an error instead. How can I force a JSON response with JAX-RS?

user465001
  • 806
  • 13
  • 29

2 Answers2

1

I was working on this project using Netbeans to auto-generate the code. First, it created entity classes from a database, then rest classes to access the entity classes, and finally it auto-generated a rest client using Knockout.js.

However, Netbeans did not add org.json, com.sun.jersey, and com.sun.jersey to the pom.xml file. I added the above dependencies and now, I can get json responses as expected.

user465001
  • 806
  • 13
  • 29
-1

If you want to produce JSON only responses, you must remove the "MediaType.APPLICATION_XML" from @Produces annotation.

Elvermg
  • 427
  • 6
  • 12