This example demonstrates how to produce/consume JSON representations defined by JSR-353.
The mapping of the URI path space is presented in the following table:
URI path | Resource class | HTTP methods | Allowed values |
---|---|---|---|
/document | DocumentResource | GET | |
/document | DocumentResource | DELETE | |
/document | DocumentResource | POST | JsonObject |
/document/{id: \d+} | DocumentResource | GET | |
/document/{id: \d+} | DocumentResource | DELETE | |
/document/multiple | DocumentResource | POST | JsonArray of JsonObject s |
/document/filter | DocumentFilteringResource | POST | JsonArray of string values |
(See JsonProcessingResourceTest for more details.)
Run the example as follows:
mvn clean package jetty:run
A WADL description may be accessed at the URL:
This deploys current example using Jetty. You can access the application at http://localhost:8080/jsonp-webapp/document
You can access resources of this application also using curl:
curl -H "Content-Type: application/json" -X POST --data '[{"name":"Jersey","site":"http://jersey.java.net"},{"age":33,"phone":"158158158","name":"Foo"},{"name":"JSON-P","site":"http://jsonp.java.net"}]' http://localhost:8080/jsonp-webapp/document/multiple
curl http://localhost:8080/jsonp-webapp/document
curl http://localhost:8080/jsonp-webapp/document/1
site
attributes with values of documents containing this attribute.curl -H "Content-Type: application/json" -X POST --data '["site"]' http://localhost:8080/jsonp-webapp/document/filter