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.
  1. Open a terminal session and switch to the <Install_directory>/SampleCode/quickstart directory.
  2. Run the following command:
    gfsh start server --name=server_json --cache-xml-file=xml/Server.xml
  3. Wait for the server to start.
  4. Open a second terminal session and switch to the <Install_directory>/SampleCode/quickstart directory.
  5. Add the following jar file to the CLASSPATH environment variable:


  6. Run the following command:
    java 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.

  7. Switch to the first session and stop the cache server using the following command:
    gfsh stop server --dir=server_json

Example Source Files

Table 1. Cache configuration files, located in SampleCode/quickstart/xml
Server.xml Configures a cache to serve caching clients. The example region also is configured with a loader.

Configures a region as a client region in a client/server cache. The region's pool connects to a cacheserver listening on port 40404.

Table 2. Java program files, located in SampleCode/quickstart/quickstart
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 Javadocs