|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.smartgwt.client.core.JsObject
com.smartgwt.client.core.DataClass
com.smartgwt.client.util.JSONEncoder
public class JSONEncoder
Class for encoding objects as JSON strings.
Field Summary |
---|
Fields inherited from class com.smartgwt.client.core.JsObject |
---|
jsObj |
Constructor Summary | |
---|---|
JSONEncoder()
|
|
JSONEncoder(JavaScriptObject jsObj)
|
Method Summary | |
---|---|
static JavaScriptObject |
decode(String stringToJs)
Convert the passed string as Javascript |
String |
encode(BaseClass object)
Serialize an object as a JSON string. |
String |
encode(DataClass object)
Serialize an object as a JSON string. |
String |
encode(Object object)
Serialize an object as a JSON string. |
String |
encodeDate(Date theDate)
Encode a JavaScript Date value. |
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(JavaScriptObject jsObj)
|
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. |
Boolean |
getShowDebugOutput()
If objects that cannot be serialized to JSON are encountered during serialization, show a placeholder rather than just omitting them. |
Boolean |
getSkipInternalProperties()
If true, don't show Smart GWT internal properties when encoding and object. |
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(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(JavaScriptObject jsObj)
|
void |
setPrettyPrint(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(Boolean showDebugOutput)
If objects that cannot be serialized to JSON are encountered during serialization, show a placeholder rather than just omitting them. |
void |
setSkipInternalProperties(Boolean skipInternalProperties)
If true, don't show Smart GWT internal properties when encoding and object. |
void |
setStrictQuoting(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"). |
Methods inherited from class com.smartgwt.client.core.JsObject |
---|
isCreated, setJsObj |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public JSONEncoder()
public JSONEncoder(JavaScriptObject jsObj)
Method Detail |
---|
public static JSONEncoder getOrCreateRef(JavaScriptObject jsObj)
public void setJavaScriptObject(JavaScriptObject jsObj)
public void setCircularReferenceMarker(String circularReferenceMarker)
circularReferenceMode
.
circularReferenceMarker
- . See String
. Default value is "$$BACKREF$$"public 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(Boolean prettyPrint)
prettyPrint
- prettyPrint Default value is truepublic 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(Boolean showDebugOutput)
The resulting String will not be valid JSON and so cannot be decoded/eval()'d
showDebugOutput
- showDebugOutput Default value is falsepublic Boolean getShowDebugOutput()
The resulting String will not be valid JSON and so cannot be decoded/eval()'d
public void setSkipInternalProperties(Boolean skipInternalProperties)
skipInternalProperties
- skipInternalProperties Default value is falsepublic Boolean getSkipInternalProperties()
public void setStrictQuoting(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 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 String encodeDate(Date theDate)
By default, follows the dateFormat
setting. Override to do custom encoding.
theDate
- JavaScript date object to be serialized
public String encode(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 serialize
public 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 serialize
public 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 serialize
public static JavaScriptObject decode(String stringToJs)
stringToJs
- the string to convert
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |