Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Published by Scroll Versions from space WDESIGNER and version 24.0
Div
Excerpt
Syntax
Code Block
languagenone
set aString = anObject.classToJSON()
set aString = anObject.classToJSON(options)
Semantics

The operation classToJSON() takes any object (anObject) or array of objects and tries to map it to a JSON string aString. If this is not possible, an error is raised.
JSON types and xUML types are mapped as listed on JSON Type Mapping.

Info

classToJSON() does not support cyclic structures. When a cyclic structure is detected during serializing the given object, an exception will be thrown.

SubstitutablesanObjectAny object. 
aStringTarget JSON document as String.
options

The optional parameter is an object of type ComposerOptions.

Image Removed

Image Added

Its attribute is:

AttributeTypeDescriptionAllowed Values
compact
keepNullsBoolean
When compact
When keepNulls is true, attributes of anObject with NULL values will be rendered to the JSON
composer will generate compact JSON
object, otherwise
it will generate pretty JSON
they will be left out completely (see also chapter NULL Values). The default behavior of classToJson() (i.e. when called without options) is equivalent to
compact
keepNulls=false.true
Generate compact JSON
Render NULL attributes to the JSON object.
false
Generate pretty JSON
Leave out NULL attributes (default).
keepNulls
compactBoolean
When keepNulls
When compact is true,
attributes of anObject with NULL values will be rendered to the JSON object, otherwise they will be left out completely (see also chapter NULL Values)
the JSON composer will generate compact JSON, otherwise it will generate pretty JSON. The default behavior of classToJson() (i.e. when called without options) is equivalent to
keepNulls
compact=false.true
Render NULL attributes to the JSON object
Generate compact JSON.
false
Leave out NULL attributes
Generate pretty JSON (default).
writeTypeDiscriminatorBoolean

Multiexcerpt include
SpaceWithExcerptINTERNAL
MultiExcerptNamewriteTypeDiscriminator
PageWithExcerptINTERNAL:_designer_excerpts_asl
shouldDisplayInlineCommentsInIncludesfalse
This is necessary if you want to convert the generated JSON back to an xUML class using jsonToClass().

Runtime versions before 2021.6 will ignore the value.

trueWrite xUML type discriminator (default).
falseDo not write xUML type discriminator.
Examples
Code Block
languagenone
set addressAsJSONDocument = myAddress.classToJSON();

Multiexcerpt include
SpaceWithExcerptINTERNAL
MultiExcerptNameJSONAdapter_Example
PageWithExcerptINTERNAL:_designer_examples
shouldDisplayInlineCommentsInIncludesfalse

Multiexcerpt include
SpaceWithExcerptINTERNAL
MultiExcerptNameJSONAdapter_Example
PageWithExcerptINTERNAL:_designer_examples
shouldDisplayInlineCommentsInIncludesfalse