set aString = anObject.classToExtendedJson()
set aString = anObject.classToExtendedJson(format)
set aString = anObject.classToExtendedJson(options)
Semantics
The operation classToExtendedJson() takes any object (anObject) and tries to map it to an Extended JSON string aString.
In opposition to classToJSON, classToExtendedJson() preserves the order of attributes of the converted class. JSON types and xUML types are mapped as listed in chapter jsonToClass. These details also refer to Extended JSON.
If the conversion is not possible, an error is raised.
classToExtendedJSON() does not support cyclic structures. When a cyclic structure is detected during serializing the given object, an exception will be thrown.
Runtimes before 2023.1 Trying to serialize a cyclic structure leads to a service crash.
You can hide attributes from being serialized by applying stereotype <<E2EPrivate>>. Refer to Hiding Attributes From Interfaces for more information.
Substitutables
anObject
Any object.
aString
Target Extended JSON document as String.
format
String that specifies the format of the Extended JSON that should be produced (more details see options below).
options
This optional parameter is an object of type ExtendedJSONComposerOptions.
Its attributes are:
Attribute
Type
Description
Allowed Values
format
String
Use format to specify which kind of Extended JSON should be produced: canonical or relaxed Extended JSON.
canonical
Produce canonical Extended JSON (default).
relaxed
Produce relaxed Extended JSON.
keepNulls
Boolean
When keepNulls is true, attributes of anObject with NULL values will be rendered to the Extended JSON object, otherwise 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 keepNulls=false.
true
Render NULL attributes to the Extended JSON string.
false
Leave out NULL attributes (default).
writeTypeDiscriminator
Boolean
Runtime 2021.6 Use writeTypeDiscriminator to suppress the generation of xUML type properties ("e2e:type") to the generated JSON. If this option is true, the Runtime will write the original xUML type to the generated JSON in form of "e2e:type": "<name of the original xUML type>" if the type being serialized does not match the expected metadata. This is necessary if you want to convert the generated Extended JSON back to an xUML class using extendedJSONToClass() Operation.
In contrast to classToJSON, writeTypeDiscriminator defaults to false for classToExtendedJson().
true
Write xUML type discriminator.
false
Do not write xUML type discriminator (default).
Examples
NONE
set aMongoDBdocument = myAddress.classToExtendedJson();
set aMongoDBdocument = myAddress.classToExtendedJson("relaxed");
Example File (Builder project Add-ons/MongoDB):
<your example path>\Add-ons\MongoDB\uml\simpleMongoDbAccess.xml