JSON Operations

classToJSON

Syntax
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.

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.

Its attribute is:

AttributeTypeDescriptionAllowed Values
keepNullsBooleanWhen keepNulls 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 default behavior of classToJson() (i.e. when called without options) is equivalent to keepNulls=false.trueRender NULL attributes to the JSON object.
falseLeave out NULL attributes (default).
compactBooleanWhen compact is true, 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 compact=false.trueGenerate compact JSON.
falseGenerate pretty JSON (default).
writeTypeDiscriminatorBoolean

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 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
set addressAsJSONDocument = myAddress.classToJSON();

JSONAdapter_Example

Click the icon to download a simple example model that shows the usage of the JSON adapter (classToJSON) in Scheer PAS Designer.

On this Page:

JSONAdapter_Example

Click the icon to download a simple example model that shows the usage of the JSON adapter (classToJSON) in Scheer PAS Designer.

classToExtendedJSON

Syntax
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() Operation, classToExtendedJson() preserves the order of attributes of the converted class. JSON types and xUML types are mapped as listed in chapter jsonToClass() Operation. 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.

SubstitutablesanObjectAny object. 
aStringTarget Extended JSON document as String.
formatString 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:

AttributeTypeDescriptionAllowed Values
formatStringUse format to specify which kind of Extended JSON should be produced: canonical or relaxed Extended JSON.canonicalProduce canonical Extended JSON (default).
relaxedProduce relaxed Extended JSON.
keepNullsBooleanWhen 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.trueRender NULL attributes to the Extended JSON string.
falseLeave out NULL attributes (default).
writeTypeDiscriminatorBoolean

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() Operation, writeTypeDiscriminator defaults to false for classToExtendedJson().

trueWrite xUML type discriminator.
falseDo not write xUML type discriminator (default).
Examples
set aMongoDBdocument = myAddress.classToExtendedJson();set aMongoDBdocument = myAddress.classToExtendedJson("relaxed");

For more information on Extended JSON refer to MongoDB Extended JSON.

jsonToClass

Syntax
set anObject = aString.jsonToClass()
set anObject = jsonToClass(literal)
Semantics

The operation jsonToClass() takes an JSON string (aString) and tries to map it to anObject. If this is not possible, an error is raised.

By default, the following mapping rules apply:

  • JSON attributes are mapped to class attributes having the same name.
  • Attributes not defined in the target class are ignored.

For more mapping details refer to JSON Type Mapping.

SubstitutablesaStringA JSON document as String.
anObjectTarget object, can be any object.
literalString literal.
Examples
set myAddress = addressAsJSONDocument.jsonToClass();

The action script below creates an object of type Address. An output object flow state named myAddress of type Address needs to be defined in the activity diagram.

create myAddress;
set myAddress = addressAsJSONDocument.jsonToClass();

The example below shows how to specify the xUML type at runtime, e.g. if using a derived class.

{
  "e2e:type":"urn:json.e2e.ch.AddressWithEmail",
  "name":"John Snow",
  "company":"Winter & Partners",
  "mailaddress":"john.snow@winter.com"
} 

The xUML type is declared by the attribute "e2e:type". The type has to be specified like <xml_namespace>.<classname>

For more information on JSON refer to the JSON Homepage or to RFC 4627.

  • No labels