public class JSONFormatter extends Object
JSONFormatter has a static method fromJSON(String)
to convert a JSON
document into a PdxInstance
and a static method toJSON(PdxInstance)
to convert a PdxInstance
into a JSON Document.
Using these methods an applications may convert a JSON document into a PdxInstance for storing in the cache. Indexes can then be defined on the PdxInstances so that queries can be performed using OQL. Queries will return PdxInstances and these can be turned back back into JSON documents using JSONFormatter.
JSONFormatter treats values in a json document as number(byte, short, int, long..), string, array, object, 'true', 'false' or 'null'. These correspond to the following java types:
JSON | Java |
---|---|
object | PdxInstance |
arrays | LinkedList |
BigDecimal | BigDecimal |
BigInterger | BigInteger |
Double | double |
float | float |
boolean | boolean |
Integer | byte, short or int |
null | null |
Modifier and Type | Field and Description |
---|---|
static String |
JSON_CLASSNAME |
static String |
SORT_JSON_FIELD_NAMES_PROPERTY
By setting "gemfire.sort-json-field-names" to true, enables serialization of JSON field in JSON
document to be sorted.
|
Constructor and Description |
---|
JSONFormatter() |
JSONFormatter(RegionService regionService) |
Modifier and Type | Method and Description |
---|---|
static PdxInstance |
fromJSON(byte[] jsonByteArray)
Converts a JSON document into a PdxInstance
|
static PdxInstance |
fromJSON(String jsonString)
Converts a JSON document into a PdxInstance
|
String |
fromPdxInstance(PdxInstance pdxInstance)
Converts a PdxInstance into a JSON document
|
RegionService |
getRegionService() |
static String |
toJSON(PdxInstance pdxInstance)
Converts a PdxInstance into a JSON document
|
static byte[] |
toJSONByteArray(PdxInstance pdxInstance)
Converts a PdxInstance into a JSON document in byte-array form
|
byte[] |
toJsonByteArrayFromPdxInstance(PdxInstance pdxInstance)
Converts a PdxInstance into a JSON document in byte-array form
|
PdxInstance |
toPdxInstance(Object json)
Converts a JSON document into a PdxInstance
|
public static final String JSON_CLASSNAME
public static final String SORT_JSON_FIELD_NAMES_PROPERTY
public JSONFormatter()
public JSONFormatter(RegionService regionService)
public RegionService getRegionService()
public static PdxInstance fromJSON(String jsonString)
JSONFormatterException
- if unable to parse the JSON documentpublic static PdxInstance fromJSON(byte[] jsonByteArray)
JSONFormatterException
- if unable to parse the JSON documentpublic PdxInstance toPdxInstance(Object json)
json
- either a json string or a byte[]JSONFormatterException
- if unable to parse the JSON documentpublic static String toJSON(PdxInstance pdxInstance)
JSONFormatterException
- if unable to create the JSON documentpublic String fromPdxInstance(PdxInstance pdxInstance)
JSONFormatterException
- if unable to create the JSON documentpublic static byte[] toJSONByteArray(PdxInstance pdxInstance)
JSONFormatterException
- if unable to create the JSON documentpublic byte[] toJsonByteArrayFromPdxInstance(PdxInstance pdxInstance)
JSONFormatterException
- if unable to create the JSON document