Working With JSON Document in Gemfire Cache
A quick tutorial, with code, describing how to store a JSON document in a Gemfire cache, from the very first step of setting up the environment.
Join the DZone community and get the full member experience.Join For Free
JSON Document Store in Gemfire Cache.
Let us consider below JSON needs to stored in Gemfire Cache.
Let us set up the environment; it involves Server and Client setup.
The server configuration looks like below.
The cache server configures a cache to serve caching clients. The Region 'jsonPersonRegion' also is configured with a loader.
Above Cache has been configured with port 40404, region name is 'jsonPersonRegion' and region is REPLICATED type. If data is in sync with all the nodes then it is REPLICATED.
Below is how the client is setup:
Client cache configures a region as a client region in a client/server cache. The region's pool connects to the cache server.
Below is the cache client code which stores the above json document and does query on the region.
The JSONFormatter API allows you to put JSON formatted documents into regions and retrieve them later by storing the documents internally as PdxInstances.
You can then use the
JSONFormatter to convert the PdxInstance results back into the JSON document.
Creates a PdxInstance from a JSON byte array. Returns the PdxInstance
Creates a PdxInstance from a JSON string. Returns the PdxInstance.
Reads a PdxInstance and returns a JSON string.
Reads a PdxInstance and returns a JSON byte array.
Opinions expressed by DZone contributors are their own.