public class GSONHandle extends BaseHandle<InputStream,String> implements BufferableHandle, ContentHandle<com.google.gson.JsonElement>, JSONReadHandle, JSONWriteHandle, StructureReadHandle, StructureWriteHandle
A GSONHandle represents JSON content as a GSON JsonElement for reading or writing. You must install the GSON library to use this class.
UNKNOWN_LENGTH| Constructor and Description |
|---|
GSONHandle()
Zero-argument constructor.
|
GSONHandle(com.google.gson.JsonElement content)
Provides a handle on JSON content as a tree.
|
| Modifier and Type | Method and Description |
|---|---|
void |
fromBuffer(byte[] buffer)
Sets the content of the handle by copying from a byte array buffer encoded in UTF-8.
|
com.google.gson.JsonElement |
get()
Returns the root node of the JSON tree.
|
com.google.gson.JsonParser |
getParser()
Returns the parser used to construct element objects from JSON.
|
static ContentHandleFactory |
newFactory()
Creates a factory to create a GSONHandle instance for a JsonElement node.
|
void |
set(com.google.gson.JsonElement content)
Assigns a JSON tree as the content.
|
void |
setFormat(Format format)
Restricts the format to JSON.
|
byte[] |
toBuffer()
Copies the content of the handle to a byte array buffer encoded in UTF-8.
|
String |
toString()
Returns the JSON tree as a string.
|
GSONHandle |
with(com.google.gson.JsonElement content)
Assigns a JSON tree as the content and returns the handle.
|
getByteLength, getFormat, getMimetype, getServerTimestamp, setByteLength, setMimetype, setServerTimestamppublic GSONHandle()
Zero-argument constructor.
public GSONHandle(com.google.gson.JsonElement content)
Provides a handle on JSON content as a tree.
content - the JSON root element of the tree.public static ContentHandleFactory newFactory()
Creates a factory to create a GSONHandle instance for a JsonElement node.
public com.google.gson.JsonParser getParser()
Returns the parser used to construct element objects from JSON.
public com.google.gson.JsonElement get()
Returns the root node of the JSON tree.
get in interface ContentHandle<com.google.gson.JsonElement>public void set(com.google.gson.JsonElement content)
Assigns a JSON tree as the content.
set in interface ContentHandle<com.google.gson.JsonElement>content - the JSON root element.public GSONHandle with(com.google.gson.JsonElement content)
Assigns a JSON tree as the content and returns the handle.
content - the JSON root element.public void setFormat(Format format)
Restricts the format to JSON.
setFormat in interface ContentDescriptorsetFormat in class BaseHandle<InputStream,String>format - the format of the contentpublic void fromBuffer(byte[] buffer)
BufferableHandleSets the content of the handle by copying from a byte array buffer encoded in UTF-8.
fromBuffer in interface BufferableHandlebuffer - the byte arraypublic byte[] toBuffer()
BufferableHandleCopies the content of the handle to a byte array buffer encoded in UTF-8.
toBuffer in interface BufferableHandleCopyright © 2013-2017 MarkLogic Corporation.