JSON Example
JSON Example
In this example you store a JSON document in a GemFire cache and query the document.
Running the Example
Note: To run this example, you must have terminal sessions configured for the QuickStart
examples, as described in Setting Up Your Environment for Running the Examples.
- Open a terminal session and switch to the <Install_directory>/SampleCode/quickstart directory.
- Run the following command:
gfsh start server --name=server_json --cache-xml-file=xml/Server.xml --classpath="$GEMFIRE/SampleCode/quickstart/classes"
- Wait for the server to start.
- Open a second terminal session and switch to the <Install_directory>/SampleCode/quickstart directory.
- Run the following command:
java -cp "$GEMFIRE/SampleCode/quickstart/classes:$GEMFIRE/lib/server-dependencies.jar" quickstart.JSONClient
The client displays the following JSON document:
{ "firstName" : "John", "lastName" : "Smith", "age" : 25, "address" : { "streetAddress" : "21 2nd Street", "city" : "New York", "state" : "NY", "postalCode" : "10021" }, "phoneNumber" : [ { "type" : "home", "number" : "212 555-1234" }, { "type" : "fax", "number" : "646 555-4567" } ] }
The client retrieves the JSON document, queries it, and displays the results.
- Switch to the first session and stop
the cache server using the following command:
gfsh stop server --dir=server_json
Example Source Files
Server.xml | Configures a cache to serve caching clients. The example region also is configured with a loader. |
JsonClient.xml |
Configures a region as a client region in a client/server cache. The region's pool connects to a cacheserver listening on port 40404. |
JSONClient.java | Creates a client that stores a JSON document in the cache and then queries the document. |
SimpleCacheLoader.java | A very simple CacheLoader implementation |
Related Topics |
---|
Adding JSON Documents to the GemFire Cache |
Related Javadocs
- com.gemstone.gemfire.pdx.JSONFormatter
- com.gemstone.gemfire.pdx.PdxInstance