Class JSONEncoder
- All Implemented Interfaces:
- HasHandlers
- 
Field SummaryFields inherited from class com.smartgwt.client.core.BaseClassconfig, configOnly, factoryCreated, factoryProperties, id, scClassName
- 
Constructor SummaryConstructors
- 
Method SummaryModifier and TypeMethodDescriptioncreate()static JavaScriptObjectConvert the passed string as JavascriptSerialize an object as a JSON string.Serialize an object as a JSON string.Serialize an object as a JSON string.encodeDate(Date theDate) Encode a JavaScript Date value.The string marker used to represent circular references.What the JSONEncoder should do if it encounters a circular reference.Format for encoding JavaScript Date values in JSON.By default, obscure non-printable characters such as DC3 (Device Control 3, U+0013 hexadecimal) will be escaped according to JSON standards.getJsObj()static JSONEncodergetOrCreateRef(JavaScriptObject jsObj) Whether to add indentation to the returned JSON string.Controls the output of the JSONEncoder when instances of Smart GWT classes (eg a ListGrid) are included in the data to be serialized.If objects that cannot be serialized to JSON are encountered during serialization, show a placeholder rather than just omitting them.If true, don't show Smart GWT internal properties when encoding an object.If true, don't include properties with null values when encoding an object.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").booleansetCircularReferenceMarker(String circularReferenceMarker) The string marker used to represent circular references.setCircularReferenceMode(JSONCircularReferenceMode circularReferenceMode) What the JSONEncoder should do if it encounters a circular reference.setDateFormat(JSONDateFormat dateFormat) Format for encoding JavaScript Date values in JSON.setEscapeNonPrintable(Boolean escapeNonPrintable) By default, obscure non-printable characters such as DC3 (Device Control 3, U+0013 hexadecimal) will be escaped according to JSON standards.voidsetPrettyPrint(Boolean prettyPrint) Whether to add indentation to the returned JSON string.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.setShowDebugOutput(Boolean showDebugOutput) If objects that cannot be serialized to JSON are encountered during serialization, show a placeholder rather than just omitting them.setSkipInternalProperties(Boolean skipInternalProperties) If true, don't show Smart GWT internal properties when encoding an object.setSkipNullValues(Boolean skipNullValues) If true, don't include properties with null values when encoding an object.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.BaseClassaddDynamicProperty, 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
- 
Constructor Details- 
JSONEncoderpublic JSONEncoder()
- 
JSONEncoder
 
- 
- 
Method Details- 
getOrCreateRef
- 
setJavaScriptObject- Overrides:
- setJavaScriptObjectin class- BaseClass
 
- 
create
- 
isCreatedpublic boolean isCreated()
- 
getJsObj
- 
getOrCreateJsObj- Overrides:
- getOrCreateJsObjin class- BaseClass
 
- 
setCircularReferenceMarkerpublic JSONEncoder setCircularReferenceMarker(String circularReferenceMarker) throws IllegalStateException The string marker used to represent circular references. SeecircularReferenceMode.- Parameters:
- circularReferenceMarker- New circularReferenceMarker value. Default value is "$$BACKREF$$"
- Returns:
- JSONEncoderinstance, for chaining setter calls
- Throws:
- IllegalStateException- this property cannot be changed after the underlying component has been created
 
- 
getCircularReferenceMarkerThe string marker used to represent circular references. SeecircularReferenceMode.- Returns:
- Current circularReferenceMarker value. Default value is "$$BACKREF$$"
 
- 
setCircularReferenceModepublic JSONEncoder setCircularReferenceMode(JSONCircularReferenceMode circularReferenceMode) throws IllegalStateException What the JSONEncoder should do if it encounters a circular reference.- Parameters:
- circularReferenceMode- New circularReferenceMode value. Default value is "path"
- Returns:
- JSONEncoderinstance, for chaining setter calls
- Throws:
- IllegalStateException- this property cannot be changed after the underlying component has been created
 
- 
getCircularReferenceModeWhat the JSONEncoder should do if it encounters a circular reference.- Returns:
- Current circularReferenceMode value. Default value is "path"
 
- 
setDateFormatFormat for encoding JavaScript Date values in JSON. SeeJSONDateFormatfor valid options, or overrideencodeDate()to do something custom.- Parameters:
- dateFormat- New dateFormat value. Default value is "xmlSchema"
- Returns:
- JSONEncoderinstance, for chaining setter calls
- Throws:
- IllegalStateException- this property cannot be changed after the underlying component has been created
 
- 
getDateFormatFormat for encoding JavaScript Date values in JSON. SeeJSONDateFormatfor valid options, or overrideencodeDate()to do something custom.- Returns:
- Current dateFormat value. Default value is "xmlSchema"
 
- 
setEscapeNonPrintableBy default, obscure non-printable characters such as DC3 (Device Control 3, U+0013 hexadecimal) will be escaped according to JSON standards. ECMA-404 / The JSON Data Interchange Format requires the quotation mark (U+0022), reverse solidus (U+005C), and control characters (U+0000 through U+001F) to be escaped.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 escapeNonPrintableto 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).- Parameters:
- escapeNonPrintable- New escapeNonPrintable value. Default value is true
- Returns:
- JSONEncoderinstance, for chaining setter calls
 
- 
getEscapeNonPrintableBy default, obscure non-printable characters such as DC3 (Device Control 3, U+0013 hexadecimal) will be escaped according to JSON standards. ECMA-404 / The JSON Data Interchange Format requires the quotation mark (U+0022), reverse solidus (U+005C), and control characters (U+0000 through U+001F) to be escaped.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 escapeNonPrintableto 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).- Returns:
- Current escapeNonPrintable value. Default value is true
 
- 
setPrettyPrintWhether to add indentation to the returned JSON string. This makes the returned JSON much easier to read but adds size. Note that when delivering JSON responses compressed, the size difference between prettyPrinted JSON and normal JSON is negligible.- Parameters:
- prettyPrint- New prettyPrint value. Default value is true
- Returns:
- JSONEncoderinstance, for chaining setter calls
- Throws:
- IllegalStateException- this property cannot be changed after the underlying component has been created
 
- 
getPrettyPrintWhether to add indentation to the returned JSON string. This makes the returned JSON much easier to read but adds size. Note that when delivering JSON responses compressed, the size difference between prettyPrinted JSON and normal JSON is negligible.- Returns:
- Current prettyPrint value. Default value is true
 
- 
setSerializeInstancespublic JSONEncoder setSerializeInstances(JSONInstanceSerializationMode serializeInstances) throws IllegalStateException Controls the output of the JSONEncoder when instances of Smart GWT classes (eg a ListGrid) are included in the data to be serialized. SeeJSONInstanceSerializationMode.Note that the JSONEncoder does not support a format that will recreate the instance if passed to decode() or eval(). - Parameters:
- serializeInstances- New serializeInstances value. Default value is "long"
- Returns:
- JSONEncoderinstance, for chaining setter calls
- Throws:
- IllegalStateException- this property cannot be changed after the underlying component has been created
 
- 
getSerializeInstancesControls the output of the JSONEncoder when instances of Smart GWT classes (eg a ListGrid) are included in the data to be serialized. SeeJSONInstanceSerializationMode.Note that the JSONEncoder does not support a format that will recreate the instance if passed to decode() or eval(). - Returns:
- Current serializeInstances value. Default value is "long"
 
- 
setShowDebugOutputIf objects that cannot be serialized to JSON are encountered during serialization, show a placeholder rather than just omitting them.The resulting String will not be valid JSON and so cannot be decoded/eval()'d - Parameters:
- showDebugOutput- New showDebugOutput value. Default value is false
- Returns:
- JSONEncoderinstance, for chaining setter calls
- Throws:
- IllegalStateException- this property cannot be changed after the underlying component has been created
 
- 
getShowDebugOutputIf objects that cannot be serialized to JSON are encountered during serialization, show a placeholder rather than just omitting them.The resulting String will not be valid JSON and so cannot be decoded/eval()'d - Returns:
- Current showDebugOutput value. Default value is false
 
- 
setSkipInternalPropertiespublic JSONEncoder setSkipInternalProperties(Boolean skipInternalProperties) throws IllegalStateException If true, don't show Smart GWT internal properties when encoding an object.- Parameters:
- skipInternalProperties- New skipInternalProperties value. Default value is false
- Returns:
- JSONEncoderinstance, for chaining setter calls
- Throws:
- IllegalStateException- this property cannot be changed after the underlying component has been created
 
- 
getSkipInternalPropertiesIf true, don't show Smart GWT internal properties when encoding an object.- Returns:
- Current skipInternalProperties value. Default value is false
 
- 
setSkipNullValuesIf true, don't include properties with null values when encoding an object.- Parameters:
- skipNullValues- New skipNullValues value. Default value is false
- Returns:
- JSONEncoderinstance, for chaining setter calls
- Throws:
- IllegalStateException- this property cannot be changed after the underlying component has been created
 
- 
getSkipNullValuesIf true, don't include properties with null values when encoding an object.- Returns:
- Current skipNullValues value. Default value is false
 
- 
setStrictQuotingWhether all property names should be quoted, or only those property names that are not valid identifiers or are JavaScript reserved words (such as "true").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.- Parameters:
- strictQuoting- New strictQuoting value. Default value is true
- Returns:
- JSONEncoderinstance, for chaining setter calls
- Throws:
- IllegalStateException- this property cannot be changed after the underlying component has been created
 
- 
getStrictQuotingWhether all property names should be quoted, or only those property names that are not valid identifiers or are JavaScript reserved words (such as "true").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.- Returns:
- Current strictQuoting value. Default value is true
 
- 
encodeDateEncode a JavaScript Date value.By default, follows the dateFormatsetting. To override the date format, all Dates should be converted to Strings beforehand.- Parameters:
- theDate- JavaScript date object to be serialized
- Returns:
- value to be included in result. If this value is intended to appear as a String it should include quotes (")
 
- 
encodeSerialize an object as a JSON string.Because GWT does not support Java reflection, JSON encoding cannot discover the properties of an arbitrary Java POJO. The following objects are supported: - any primitive type (String, Date, Number, Boolean)
- any Map or Collection in any level of nesting
- DataClass (Record's superclass) and RecordList
- any widget (see +link{JSONEncoder.serializeInstances})
- JavaScriptObject
- an Array containing any of the above
 Note that using the String produced by this API with JSON.decodewill not successfully preserve dates. UseJSONEncoder.setDateFormat"dateConstructor" to have dates round-trip properly.- Parameters:
- object- object to serialize
- Returns:
- object encoded as a JSON String
 
- 
encodeSerialize an object as a JSON string.Because GWT does not support Java reflection, JSON encoding cannot discover the properties of an arbitrary Java POJO. The following objects are supported: - any primitive type (String, Date, Number, Boolean)
- any Map or Collection in any level of nesting
- DataClass (Record's superclass) and RecordList
- any widget (see +link{JSONEncoder.serializeInstances})
- JavaScriptObject
- an Array containing any of the above
 Note that using the String produced by this API with JSON.decodewill not successfully preserve dates. UseJSONEncoder.setDateFormat"dateConstructor" to have dates round-trip properly.- Parameters:
- object- object to serialize
- Returns:
- object encoded as a JSON String
 
- 
encodeSerialize an object as a JSON string.Because GWT does not support Java reflection, JSON encoding cannot discover the properties of an arbitrary Java POJO. The following objects are supported: - any primitive type (String, Date, Number, Boolean)
- any Map or Collection in any level of nesting
- DataClass (Record's superclass) and RecordList
- any widget (see +link{JSONEncoder.serializeInstances})
- JavaScriptObject
- an Array containing any of the above
 Note that using the String produced by this API with JSON.decodewill not successfully preserve dates. UseJSONEncoder.setDateFormat"dateConstructor" to have dates round-trip properly.- Parameters:
- object- object to serialize
- Returns:
- object encoded as a JSON String
 
- 
decodeConvert the passed string as Javascript- Parameters:
- stringToJs- the string to convert
- Returns:
- the JavaScriptObject upon evaluation
 
 
-