public class JSONEncoder extends BaseClass
config, factoryCreated, factoryProperties, id, scClassName
Constructor and Description |
---|
JSONEncoder() |
JSONEncoder(com.google.gwt.core.client.JavaScriptObject jsObj) |
Modifier and Type | Method and Description |
---|---|
com.google.gwt.core.client.JavaScriptObject |
create() |
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.
|
com.google.gwt.core.client.JavaScriptObject |
getJsObj() |
com.google.gwt.core.client.JavaScriptObject |
getOrCreateJsObj() |
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").
|
boolean |
isCreated() |
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").
|
applyFactoryProperties, asSGWTComponent, createJsObj, destroy, doAddHandler, doInit, error, error, errorIfNotCreated, fireEvent, getAttribute, getAttributeAsBoolean, getAttributeAsDate, getAttributeAsDouble, getAttributeAsElement, getAttributeAsFloat, getAttributeAsInt, getAttributeAsJavaScriptObject, getAttributeAsMap, getAttributeAsString, getAttributeAsStringArray, getClassName, getConfig, getHandlerCount, getID, getRef, getScClassName, getTestInstance, hasAutoAssignedID, internalSetID, internalSetID, isFactoryCreated, onBind, onInit, registerID, setAttribute, setAttribute, setAttribute, setAttribute, setAttribute, setAttribute, setAttribute, setAttribute, setAttribute, setAttribute, setAttribute, setAttribute, setAttribute, setAttribute, setAttribute, setAttribute, setAttribute, setAttribute, setAttribute, setAttribute, setConfig, setFactoryCreated, setID, setProperty, setProperty, setProperty, setProperty, setScClassName
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)
setJavaScriptObject
in class BaseClass
public com.google.gwt.core.client.JavaScriptObject create()
public com.google.gwt.core.client.JavaScriptObject getJsObj()
public com.google.gwt.core.client.JavaScriptObject getOrCreateJsObj()
getOrCreateJsObj
in class BaseClass
public void setCircularReferenceMarker(java.lang.String circularReferenceMarker) throws java.lang.IllegalStateException
circularReferenceMode
.circularReferenceMarker
- Default value is "$$BACKREF$$"java.lang.IllegalStateException
- this property cannot be changed after the underlying component has been createdpublic java.lang.String getCircularReferenceMarker()
circularReferenceMode
.public void setCircularReferenceMode(JSONCircularReferenceMode circularReferenceMode) throws java.lang.IllegalStateException
circularReferenceMode
- Default value is "path"java.lang.IllegalStateException
- this property cannot be changed after the underlying component has been createdpublic JSONCircularReferenceMode getCircularReferenceMode()
public void setDateFormat(JSONDateFormat dateFormat) throws java.lang.IllegalStateException
JSONDateFormat
for valid
options, or override JSONEncoder.encodeDate()
to do something
custom.dateFormat
- Default value is "xmlSchema"java.lang.IllegalStateException
- this property cannot be changed after the underlying component has been createdpublic JSONDateFormat getDateFormat()
JSONDateFormat
for valid
options, or override JSONEncoder.encodeDate()
to do something
custom.public void setPrettyPrint(java.lang.Boolean prettyPrint) throws java.lang.IllegalStateException
prettyPrint
- Default value is truejava.lang.IllegalStateException
- this property cannot be changed after the underlying component has been createdpublic java.lang.Boolean getPrettyPrint()
public void setSerializeInstances(JSONInstanceSerializationMode serializeInstances) throws java.lang.IllegalStateException
JSONInstanceSerializationMode
. Note that the JSONEncoder does not support a format that will recreate the instance if passed to decode() or eval().
serializeInstances
- Default value is "long"java.lang.IllegalStateException
- this property cannot be changed after the underlying component has been createdpublic 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) throws java.lang.IllegalStateException
The resulting String will not be valid JSON and so cannot be decoded/eval()'d
showDebugOutput
- Default value is falsejava.lang.IllegalStateException
- this property cannot be changed after the underlying component has been createdpublic 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) throws java.lang.IllegalStateException
skipInternalProperties
- Default value is falsejava.lang.IllegalStateException
- this property cannot be changed after the underlying component has been createdpublic java.lang.Boolean getSkipInternalProperties()
public void setStrictQuoting(java.lang.Boolean strictQuoting) throws java.lang.IllegalStateException
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
- Default value is truejava.lang.IllegalStateException
- this property cannot be changed after the underlying component has been createdpublic 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. To override the date format, all Dates should be converted to Strings beforehand.
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