You are viewing an old version of this page. View the current version.

Compare with Current View Page History

Version 1 Next »

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.

JSON types and E2E types are mapped as listed below (for more information on E2E base types see Base Types).

JSON TypeE2E Type
stringString
intInteger
numberFloat
true/falseBoolean
string (base64 encoded)Blob
string (XML scheme dateTime)DateTime
arrayArray
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();

Below, a sample JSON string is shown to illustrate the mapping executed by the jsonlToClass() operation. The JSON string is mapped to an instance of Address as shown in the activity diagram.

{"name":"J. Smith", "street":"10, High Street"}

Find below a second example, showing how to specify the E2E type at runtime, e.g. if using a derived class.

{"e2e:type":"urn:json.e2e.ch.AddressWithMail","name":"J. Smith", "street":"10, High Street","mailaddress":"support@e2e.ch"} 

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

Example File (Builder project Add-ons/JSON):

<your example path>\Add-ons\JSON\uml\userManager.xml

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

  • No labels