Skip to content

Commit

Permalink
Properly document mapping of samm-c:Either to JSON payloads
Browse files Browse the repository at this point in the history
Changes:
- Update documentation.

Fixes: #271
  • Loading branch information
Yauhenikapl committed Jan 18, 2024
1 parent b8e735a commit 247194d
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 2 deletions.
2 changes: 1 addition & 1 deletion documentation/modules/ROOT/pages/modeling-guidelines.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ Aspects each containing a single Collection.
Describes a Property whose value can have one of two possible types (a disjoint union). This
Characteristic is special since it does not directly define a data type. The data type is defined in
the two Characteristics which define the left and right value of the disjoint union. Also see
xref:characteristics.adoc#either-characteristic[Either].
xref:characteristics.adoc#either-characteristic[Either] and xref:payload.adoc[Mapping to JSON].

Example:

Expand Down
43 changes: 42 additions & 1 deletion documentation/modules/ROOT/pages/payloads.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -145,11 +145,12 @@ the data. The mappings are described in the following table.
.2+| Encoded binary data
| `xsd:hexBinary` | String
| `xsd:base64Binary` | String
.3+| Miscellaneous types
.4+| Miscellaneous types
| `xsd:anyURI` | String
| `samm:curie` | String
| `rdf:langString`
| A JSON object with a structure as described in the rules above.
| `samm-c:Either` | A JSON object with the left field and the value, which is one of the types proposed in `xref:characteristics.adoc#either-characteristic[Either]`.
|===

For example, a Property `errorMessage` with effective data type `rdf:langString` and the value
Expand All @@ -174,6 +175,46 @@ A Property `errorMessages` with a Collection Characteristic and effective data t
}
----

Another one example for `samm-c:Either`, a Property `speedProperty` has Characteristic and effective data type `samm-c:Either` and the possible values
`isMoving` (`xref:datatypes.adoc#data-types[xsd:boolean]` data type) or '60' (`Number`) would be serialized in the JSON payload as follows:
[source,json]
----
{
"speedProperty": {
"left": true
}
}
or
{
"speedProperty": {
"left": 60
}
}
----

A Property `speedProperty` has Characteristic and effective data type `samm-c:Either`. Field `samm-c:left` has type `samm-c:Either` and field `samm-c:right` has type `xref:datatypes.adoc#data-types[xsd:boolean]`.
Field `samm-c:left` has possible values `isMoving` (`xref:datatypes.adoc#data-types[xsd:boolean]` data type) or '60' (`Number`). This structure would be serialized in the JSON payload as follows:
[source,json]
----
{
"speedProperty": {
"left": {
"left": 60
}
}
}
or
{
"speedProperty": {
"left": true
}
}
----


CAUTION: Due to the https://www.ecma-international.org/ecma-262/5.1/#sec-8.5[limits in the
represention of numbers] in JSON, the maximum integer number that can be used without losing
Expand Down

0 comments on commit 247194d

Please sign in to comment.