public class JSONEncoder extends DataClass
Constructor and Description |
---|
JSONEncoder() |
JSONEncoder(com.google.gwt.core.client.JavaScriptObject jsObj) |
Modifier and Type | Method and Description |
---|---|
static com.google.gwt.core.client.JavaScriptObject |
decode(java.lang.String stringToJs)
Convert the passed string as Javascript
|
java.lang.String |
encode(BaseClass object)
Serialize an object as a JSON string.
|
java.lang.String |
encode(DataClass object)
Serialize an object as a JSON string.
|
java.lang.String |
encode(java.lang.Object object)
Serialize an object as a JSON string.
|
java.lang.String |
encodeDate(java.util.Date theDate)
Encode a JavaScript Date value.
|
java.lang.String |
getCircularReferenceMarker()
The string marker used to represent circular references.
|
JSONCircularReferenceMode |
getCircularReferenceMode()
What the JSONEncoder should do if it encounters a circular reference.
|
JSONDateFormat |
getDateFormat()
Format for encoding JavaScript Date values in JSON.
|
static JSONEncoder |
getOrCreateRef(com.google.gwt.core.client.JavaScriptObject jsObj) |
java.lang.Boolean |
getPrettyPrint()
Whether to add indentation to the returned JSON string.
|
JSONInstanceSerializationMode |
getSerializeInstances()
Controls the output of the JSONEncoder when instances of Smart GWT classes (eg a ListGrid) are included in the data to
be serialized.
|
java.lang.Boolean |
getShowDebugOutput()
If objects that cannot be serialized to JSON are encountered during serialization, show a placeholder rather than just
omitting them.
|
java.lang.Boolean |
getSkipInternalProperties()
If true, don't show Smart GWT internal properties when encoding and object.
|
java.lang.Boolean |
getStrictQuoting()
Whether all property names should be quoted, or only those property names that are not valid
identifiers or are JavaScript reserved words (such as "true").
|
void |
setCircularReferenceMarker(java.lang.String circularReferenceMarker)
The string marker used to represent circular references.
|
void |
setCircularReferenceMode(JSONCircularReferenceMode circularReferenceMode)
What the JSONEncoder should do if it encounters a circular reference.
|
void |
setDateFormat(JSONDateFormat dateFormat)
Format for encoding JavaScript Date values in JSON.
|
void |
setJavaScriptObject(com.google.gwt.core.client.JavaScriptObject jsObj) |
void |
setPrettyPrint(java.lang.Boolean prettyPrint)
Whether to add indentation to the returned JSON string.
|
void |
setSerializeInstances(JSONInstanceSerializationMode serializeInstances)
Controls the output of the JSONEncoder when instances of Smart GWT classes (eg a ListGrid) are included in the data to
be serialized.
|
void |
setShowDebugOutput(java.lang.Boolean showDebugOutput)
If objects that cannot be serialized to JSON are encountered during serialization, show a placeholder rather than just
omitting them.
|
void |
setSkipInternalProperties(java.lang.Boolean skipInternalProperties)
If true, don't show Smart GWT internal properties when encoding and object.
|
void |
setStrictQuoting(java.lang.Boolean strictQuoting)
Whether all property names should be quoted, or only those property names that are not valid
identifiers or are JavaScript reserved words (such as "true").
|
doAddHandler, fireEvent, getAttribute, getAttributeAsBoolean, getAttributeAsDate, getAttributeAsDouble, getAttributeAsDoubleArray, getAttributeAsFloat, getAttributeAsInt, getAttributeAsIntArray, getAttributeAsJavaScriptObject, getAttributeAsLong, getAttributeAsMap, getAttributeAsObject, getAttributeAsRecord, getAttributeAsString, getAttributeAsStringArray, getAttributes, getHandlerCount, getJsObj, setAttribute, setAttribute, setAttribute, setAttribute, setAttribute, setAttribute, setAttribute, setAttribute, setAttribute, setAttribute, setAttribute, setAttribute, setAttribute, setAttribute, setAttribute, setAttribute, setAttribute, setAttribute, setAttribute, setAttribute, setAttribute, setAttribute, setAttribute, setAttribute, setAttributeAsJavaObject
public JSONEncoder()
public JSONEncoder(com.google.gwt.core.client.JavaScriptObject jsObj)
public static JSONEncoder getOrCreateRef(com.google.gwt.core.client.JavaScriptObject jsObj)
public void setJavaScriptObject(com.google.gwt.core.client.JavaScriptObject jsObj)
public void setCircularReferenceMarker(java.lang.String circularReferenceMarker)
circularReferenceMode
.circularReferenceMarker
- . See String
. Default value is "$$BACKREF$$"public java.lang.String getCircularReferenceMarker()
circularReferenceMode
.String
public void setCircularReferenceMode(JSONCircularReferenceMode circularReferenceMode)
circularReferenceMode
- circularReferenceMode Default value is "path"public JSONCircularReferenceMode getCircularReferenceMode()
public void setDateFormat(JSONDateFormat dateFormat)
JSONDateFormat
for valid
options, or override JSONEncoder.encodeDate
to do something
custom.dateFormat
- dateFormat Default value is "xmlSchema"public JSONDateFormat getDateFormat()
JSONDateFormat
for valid
options, or override JSONEncoder.encodeDate
to do something
custom.public void setPrettyPrint(java.lang.Boolean prettyPrint)
prettyPrint
- prettyPrint Default value is truepublic java.lang.Boolean getPrettyPrint()
public void setSerializeInstances(JSONInstanceSerializationMode serializeInstances)
JSONInstanceSerializationMode
. Note that the JSONEncoder does not support a format that will recreate the instance if passed to decode() or eval().
serializeInstances
- serializeInstances Default value is "long"public JSONInstanceSerializationMode getSerializeInstances()
JSONInstanceSerializationMode
. Note that the JSONEncoder does not support a format that will recreate the instance if passed to decode() or eval().
public void setShowDebugOutput(java.lang.Boolean showDebugOutput)
The resulting String will not be valid JSON and so cannot be decoded/eval()'d
showDebugOutput
- showDebugOutput Default value is falsepublic java.lang.Boolean getShowDebugOutput()
The resulting String will not be valid JSON and so cannot be decoded/eval()'d
public void setSkipInternalProperties(java.lang.Boolean skipInternalProperties)
skipInternalProperties
- skipInternalProperties Default value is falsepublic java.lang.Boolean getSkipInternalProperties()
public void setStrictQuoting(java.lang.Boolean strictQuoting)
Encoding only where required produces slightly shorter, more readable output which is still compatible with JavaScript's eval():
{ someProp : "someValue", "true" : "otherValue", otherProp : "otherValue" }.. but is not understood by many server-side JSON parser implementations.
strictQuoting
- strictQuoting Default value is truepublic java.lang.Boolean getStrictQuoting()
Encoding only where required produces slightly shorter, more readable output which is still compatible with JavaScript's eval():
{ someProp : "someValue", "true" : "otherValue", otherProp : "otherValue" }.. but is not understood by many server-side JSON parser implementations.
public java.lang.String encodeDate(java.util.Date theDate)
By default, follows the dateFormat
setting.
theDate
- JavaScript date object to be serializedpublic java.lang.String encode(java.lang.Object object)
Because GWT does not support Java reflection, JSON encoding cannot discover the properties of an arbitrary Java POJO. The following objects are supported:
Note that using the String produced by this API with JSON.decode
will not
successfully preserve dates. Use JSONEncoder.setDateFormat
"dateConstructor" to have
dates round-trip properly.
object
- object to serializepublic java.lang.String encode(DataClass object)
Because GWT does not support Java reflection, JSON encoding cannot discover the properties of an arbitrary Java POJO. The following objects are supported:
Note that using the String produced by this API with JSON.decode
will not
successfully preserve dates. Use JSONEncoder.setDateFormat
"dateConstructor" to have
dates round-trip properly.
object
- object to serializepublic java.lang.String encode(BaseClass object)
Because GWT does not support Java reflection, JSON encoding cannot discover the properties of an arbitrary Java POJO. The following objects are supported:
Note that using the String produced by this API with JSON.decode
will not
successfully preserve dates. Use JSONEncoder.setDateFormat
"dateConstructor" to have
dates round-trip properly.
object
- object to serializepublic static com.google.gwt.core.client.JavaScriptObject decode(java.lang.String stringToJs)
stringToJs
- the string to convert