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 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
Code Block
languagenone
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.

Code Block
languagenone
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.

Code Block
languagenone
{
  "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.

rp
Panel
titleRelated Pages:
rde
Panel
titleRelated Documentation: