tree: 9a065b42ba7a68d215877b71b24dfef649ceedda [path history] [tgz]
  1. src/
  2. pom.xml
  3. README.MD
examples/json-processing-webapp/README.MD

JSON-P JAX-RS JSON Provider Example

This example demonstrates how to produce/consume JSON representations defined by JSR-353.

Contents

The mapping of the URI path space is presented in the following table:

URI pathResource classHTTP methodsAllowed values
/documentDocumentResourceGET
/documentDocumentResourceDELETE 
/documentDocumentResourcePOSTJsonObject
/document/{id: \d+}DocumentResourceGET 
/document/{id: \d+}DocumentResourceDELETE 
/document/multipleDocumentResourcePOSTJsonArray of JsonObjects
/document/filterDocumentFilteringResourcePOSTJsonArray of string values

(See JsonProcessingResourceTest for more details.)

Running the Example

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:

Store some documents.

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

Retrieve stored documents.

curl http://localhost:8080/jsonp-webapp/document

Retrieve a document with id 1.

curl http://localhost:8080/jsonp-webapp/document/1

Retrieve 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