public class JSONEncoder extends BaseClass
config, configOnly, 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.
|
java.lang.Boolean |
getEscapeNonPrintable()
By default, obscure non-printable characters such as DC3 (Device Control 3, U+0013 hexadecimal) will be escaped
according to JSON standards.
|
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() |
JSONEncoder |
setCircularReferenceMarker(java.lang.String circularReferenceMarker)
The string marker used to represent circular references.
|
JSONEncoder |
setCircularReferenceMode(JSONCircularReferenceMode circularReferenceMode)
What the JSONEncoder should do if it encounters a circular reference.
|
JSONEncoder |
setDateFormat(JSONDateFormat dateFormat)
Format for encoding JavaScript Date values in JSON.
|
JSONEncoder |
setEscapeNonPrintable(java.lang.Boolean escapeNonPrintable)
By default, obscure non-printable characters such as DC3 (Device Control 3, U+0013 hexadecimal) will be escaped
according to JSON standards.
|
void |
setJavaScriptObject(com.google.gwt.core.client.JavaScriptObject jsObj) |
JSONEncoder |
setPrettyPrint(java.lang.Boolean prettyPrint)
Whether to add indentation to the returned JSON string.
|
JSONEncoder |
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.
|
JSONEncoder |
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.
|
JSONEncoder |
setSkipInternalProperties(java.lang.Boolean skipInternalProperties)
If true, don't show Smart GWT internal properties when encoding and object.
|
JSONEncoder |
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").
|
addDynamicProperty, addDynamicProperty, addDynamicProperty, addDynamicProperty, applyFactoryProperties, asSGWTComponent, clearDynamicProperty, createJsObj, destroy, doAddHandler, doInit, error, error, errorIfNotCreated, fireEvent, getAttribute, getAttributeAsBoolean, getAttributeAsDate, getAttributeAsDouble, getAttributeAsElement, getAttributeAsFloat, getAttributeAsInt, getAttributeAsJavaScriptObject, getAttributeAsMap, getAttributeAsString, getAttributeAsStringArray, getClassName, getConfig, getHandlerCount, getID, getRef, getRuleScope, getScClassName, getTestInstance, hasAutoAssignedID, hasDynamicProperty, internalSetID, internalSetID, isConfigOnly, 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, setConfigOnly, setFactoryCreated, setID, setProperty, setProperty, setProperty, setProperty, setRuleScope, 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 JSONEncoder setCircularReferenceMarker(java.lang.String circularReferenceMarker) throws java.lang.IllegalStateException
circularReferenceMode
.circularReferenceMarker
- New circularReferenceMarker value. Default value is "$$BACKREF$$"JSONEncoder
instance, for chaining setter callsjava.lang.IllegalStateException
- this property cannot be changed after the underlying component has been createdpublic java.lang.String getCircularReferenceMarker()
circularReferenceMode
.public JSONEncoder setCircularReferenceMode(JSONCircularReferenceMode circularReferenceMode) throws java.lang.IllegalStateException
circularReferenceMode
- New circularReferenceMode value. Default value is "path"JSONEncoder
instance, for chaining setter callsjava.lang.IllegalStateException
- this property cannot be changed after the underlying component has been createdpublic JSONCircularReferenceMode getCircularReferenceMode()
public JSONEncoder setDateFormat(JSONDateFormat dateFormat) throws java.lang.IllegalStateException
JSONDateFormat
for valid
options, or override encodeDate()
to do something custom.dateFormat
- New dateFormat value. Default value is "xmlSchema"JSONEncoder
instance, for chaining setter callsjava.lang.IllegalStateException
- this property cannot be changed after the underlying component has been createdpublic JSONDateFormat getDateFormat()
JSONDateFormat
for valid
options, or override encodeDate()
to do something custom.public JSONEncoder setEscapeNonPrintable(java.lang.Boolean escapeNonPrintable)
These characters are very rarely
used in JSON data in web applications. If you know that your application does not use such characters in JSON data,
there can be a performance advantage to setting escapeNonPrintable
to false in order to disable the logic
for escaping these characters. This is a detectable difference only when dealing with very large JSON structures on
older browsers that do not provide native support (for example, Internet Explorer 8).
escapeNonPrintable
- New escapeNonPrintable value. Default value is trueJSONEncoder
instance, for chaining setter callspublic java.lang.Boolean getEscapeNonPrintable()
These characters are very rarely
used in JSON data in web applications. If you know that your application does not use such characters in JSON data,
there can be a performance advantage to setting escapeNonPrintable
to false in order to disable the logic
for escaping these characters. This is a detectable difference only when dealing with very large JSON structures on
older browsers that do not provide native support (for example, Internet Explorer 8).
public JSONEncoder setPrettyPrint(java.lang.Boolean prettyPrint) throws java.lang.IllegalStateException
prettyPrint
- New prettyPrint value. Default value is trueJSONEncoder
instance, for chaining setter callsjava.lang.IllegalStateException
- this property cannot be changed after the underlying component has been createdpublic java.lang.Boolean getPrettyPrint()
public JSONEncoder 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
- New serializeInstances value. Default value is "long"JSONEncoder
instance, for chaining setter callsjava.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 JSONEncoder 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
- New showDebugOutput value. Default value is falseJSONEncoder
instance, for chaining setter callsjava.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 JSONEncoder setSkipInternalProperties(java.lang.Boolean skipInternalProperties) throws java.lang.IllegalStateException
skipInternalProperties
- New skipInternalProperties value. Default value is falseJSONEncoder
instance, for chaining setter callsjava.lang.IllegalStateException
- this property cannot be changed after the underlying component has been createdpublic java.lang.Boolean getSkipInternalProperties()
public JSONEncoder 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
- New strictQuoting value. Default value is trueJSONEncoder
instance, for chaining setter callsjava.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