Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

vectorsAsArrays and recordsAsArrays attibutes for JSONEncoding #118

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion swecommon/old_xml_encoding/annex-examples.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -732,7 +732,7 @@ The following snippet shows how this datastream records are encoded using the JS

This example is based on the same datastream description as the one provided in <<enc_text_optional_fields_example,style=short%>>.

The following snippet shows how this datastream records are encoded using the XML encoding method:
The following snippet shows how this datastream records are encoded using the JSON encoding method:

[source%unnumbered,json]
----
Expand Down
2 changes: 1 addition & 1 deletion swecommon/schemas/json/DataStream.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,4 @@
]
}
]
}
}
10 changes: 10 additions & 0 deletions swecommon/schemas/json/encodings.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,16 @@
"properties": {
"type": {
"const": "JSONEncoding"
},
"recordsAsArrays": {
"type": "boolean",
"default": false,
"description": "If true, DataRecord values are encoded as JSON arrays instead of JSON objects"
},
"vectorsAsArrays": {
"type": "boolean",
"default": false,
"description": "If true, Vector values are encoded as JSON arrays instead of JSON objects"
}
},
"required": [
Expand Down
4 changes: 3 additions & 1 deletion swecommon/schemas/json/examples/spec/json-encoding.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
{
"type": "JSONEncoding"
"type": "JSONEncoding",
"recordsAsArrays": false,
"vectorsAsArrays": false
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@
[%metadata]
identifier:: /req/json-encoding-rules/record-object-valid

part:: “DataRecord” values shall be wrapped in a JSON Object.
part:: “DataRecord” values shall be wrapped either in a JSON Object or in a JSON Array. If the attribute 'recordsAsArrays' of the corresponding 'JSONEncoding' is true, all “DataRecord” values shall be encoded as JSON objects, else as JSON arrays. If the 'recordsAsArrays' or the corresponding 'JSONEncoding' is omitted, “DataRecord” values shall be encoded as JSON objects by default.

part:: The name of the JSON object members shall be the same as the “DataRecord” field names.
part:: If “DataRecord” values are encoded as JSON objects, the name of the JSON object members shall be the same as the “DataRecord” field names. The value of each JSON object member shall be chosen by following the encoding rules of the data component used as the record field with the same name. If a record field is marked as 'optional', the corresponding JSON object member can be omitted or its JSON value can be set to `null`.

part:: The value of each JSON Object member shall be chosen by following the encoding rules of the data component used as the record field with the same name.
part:: If “DataRecord” values are encoded as JSON arrays, the order of JSON array items shall be the same as the “DataRecord” fields. The value of each JSON array item shall be chosen by following the encoding rules of the data component used as the record field at the same position. If a record field is marked as 'optional', the corresponding JSON array item can be set `null`, but can not be omitted.

part:: If a record field is marked as 'optional', the corresponding JSON object member can be omitted or its JSON value can be set to `null`.
====
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
[%metadata]
identifier:: /req/json-encoding-rules/vector-object-valid

part:: “Vector” values shall be wrapped in a JSON Object.
part:: “Vector” values shall be wrapped either in a JSON Object or in a JSON Array. If the attribute 'vectorsAsArrays' of the corresponding 'JSONEncoding' is true, all “Vector” values shall be encoded as JSON objects, else as JSON arrays. If the 'vectorsAsArrays' or the corresponding 'JSONEncoding' is omitted, “Vector” values shall be encoded as JSON objects by default.

part:: The name of the JSON object members shall be the same as the “Vector” coordinate names.
part:: If “Vector” values are encoded as JSON objects, the name of the JSON object members shall be the same as the “Vector” coordinate names. The value of each JSON object member shall be chosen by following the encoding rules of the data component used as the vector coordinate field with the same name.

part:: If “Vector” values are encoded as JSON arrays, the order of JSON array items shall be the same as the “Vector” coordinate fields. The value of each JSON array item shall be chosen by following the encoding rules of the data component used as the vector coordinate field at the same position.

part:: The value of each JSON Object member shall be chosen by following the encoding rules of the data component used as the vector coordinate field with the same name.
====
32 changes: 31 additions & 1 deletion swecommon/standard/sections/annex-examples.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,7 @@ The following snippet shows how this datastream records are encoded using the JS

This example is based on the same datastream description as the one provided in <<enc_text_optional_fields_example,style=short%>>.

The following snippet shows how this datastream records are encoded using the XML encoding method:
The following snippet shows how this datastream records are encoded using the JSON encoding method:

[source%unnumbered,json]
----
Expand Down Expand Up @@ -517,6 +517,36 @@ The following snippet shows how this datastream records are encoded using the XM
----


[[enc_json_optional_fields_example_vectors_as_arrays]]
==== Datastream with records and vector fields encoded as arrays (navigation data)

This example is based on the same datastream description as the one provided in <<enc_text_optional_fields_example,style=short%>>.

The following snippet shows how this datastream records are encoded using the JSON encoding method, when `vectorsAsArrays` is `true`:

[source%unnumbered,json]
----
[
{
"time": "2007-10-23T15:46:12Z",
"speed": 15.3,
"location": [ 45.3, -90.5, 311 ]
},
{
"time": "2007-10-23T15:46:22Z",
"speed": 25.3,
"location": null
},
{
"time": "2007-10-23T15:46:32Z",
"speed": 20.6,
"location": [ 45.3, -90.6, 312 ]
},
...
]
----


[[enc_json_choice_example]]
==== Datastream with choice (navigation data)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,19 +92,18 @@ include::../requirements/encoding_rules/json/requirement3.adoc[]

==== Rules for DataRecord and Vector

“DataRecord” components are encoded using a JSON Object whose members are named like the record fields.
“DataRecord” and “Vector” components are encoded using a JSON Object whose members are named like the record fields per default. The attributes `vectorAsArrays` and `recordsAsArrays` of the corresponding JSON Encoding can be used to switch to a more compact encoding using JSON arrays.

include::../requirements/encoding_rules/json/requirement4.adoc[]

include::../requirements/encoding_rules/json/requirement5.adoc[]

When a field has its 'optional' flag set to true, its value can be either omitted or set to the literal value `null`.

See the following examples:

- <<enc_json_curve_example,style=basic%>>
- <<enc_json_weather_stream_example,style=basic%>>
- <<enc_json_optional_fields_example,style=basic%>>
- <<enc_json_optional_fields_example_vectors_as_arrays,style=basic%>>


==== Rules for DataChoice
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Encoding methods describe how structured array and stream data is encoded into a
This package includes two classes that provide definitions of simple encoding methods. They are used as descriptors of the method used to encode data component values wrapped by aggregate classes defined in the “Block Components” package. There model is shown on the diagram below:

.Simple Encodings
// FIXME this image needs to be updated for the new JSON Encoding attributes
image::figures/fig7.32.png[]

include::../requirements/uml/simple_encodings/requirement1.adoc[]
Expand All @@ -22,7 +23,11 @@ In the model provided in this standard, the encoding specification is provided s
[[uml_jsonencoding_class]]
==== JSONEncoding Class

The “JSONEncoding” class defines a method allowing encoding arbitrarily complex data as JSON. This class has no parameters.
The “JSONEncoding” class defines a method allowing encoding arbitrarily complex data as JSON. The class used to specify this encoding method is shown below:

// FIXME missing image of the JSON encoding class

The “recordsAsArrays” attribute specifies whether “DataRecord” values are encoded as JSON objects or JSON arrays. The “vectorsAsArrays” attribute specifies wether “Vector” values are encoded as JSON objects or JSON arrays. Both attributes are optional and default to false, meaning “DataRecord” and “Vector” values are per default encoded as JSON objects. The detailed rules are given in the implementation in <<encoding_rules_json>>.


[[uml_textencoding_class]]
Expand All @@ -33,7 +38,7 @@ The “TextEncoding” class defines a method allowing encoding arbitrarily comp
.TextEncoding Class
image::figures/fig7.33.png[]

The “tokenSeparator” attribute specifies the characters to use for separating each scalar value from one another. Scalar values appear sequentially in the stream alternatively with the token separator characters, in an order unambiguously defined by the data component structure. The detailed rules are given in the implementation <<encoding_rules_text>>.
The “tokenSeparator” attribute specifies the characters to use for separating each scalar value from one another. Scalar values appear sequentially in the stream alternatively with the token separator characters, in an order unambiguously defined by the data component structure. The detailed rules are given in the implementation in <<encoding_rules_text>>.

The “blockSeparator” attribute specifies characters used to mark the end of a “block”, corresponding to the complete structure defined by the data component tree (in a “DataArray”, “Matrix” or “DataStream” one block corresponds to one element, that is to say the structure defined by the “elementType” property). Stream or array data can then be composed of several blocks of the same type separated by block separator characters.

Expand Down