stellio-hub / stellio-context-broker

Stellio is an NGSI-LD compatible context broker
https://stellio.readthedocs.io
Apache License 2.0
25 stars 11 forks source link

Not an array when only one temporal instance of a given attribute #1143

Open EliottPaillard opened 2 months ago

EliottPaillard commented 2 months ago

Hello, I'm using the stellio images version 2.12.3

I noticed something not aligned with the NGSI-LD Specifications (1.8.1)

When trying to retrieve a temporal representation of an entity, an attribute which has only one instance in this time interval is represented by a JSON object and not an array of object.

The expected behaviour is described in part 4.5.7 of upper said document: "The temporal evolution of an NGSI-LD Property shall be represented as an Array of JSON-LD objects, each one representing an instance of the Property"

bobeal commented 2 months ago

Hi @EliottPaillard,

Thanks for reporting this.

This behavior is actually due to the JSON-LD compaction algorithm that flattens the arrays of one object into an object. I guess all NGSI-LD brokers have this same behavior... I will raise this point to ISG-CIM to see how to handle it (whether brokers should handle this "manually" or an "exception" should be added in the specification for this specific case).

bobeal commented 2 months ago

We discussed about this with ISG-CIM. This is indeed normal behavior of JSON-LD compaction (as stated in section 5.2.7 in https://www.w3.org/TR/json-ld11/#representing-singular-values-as-arrays). Hence, JSON-LD arrays (used for the temporal representation of attributes) comprising just one element are returned as a single element, not an array with just one element in it.

A note clarifying this behavior will be added in the next version of the specification.

bobeal commented 1 month ago

FYI, we discussed again about this with ISG-CIM. As there are other cases where single objects are forced to be wrapped as arrays, we finally decided that such temporal instances should always be returned as arrays (even if there is only one element and if it is kind of overwriting of normal JSON-LD compaction).

EliottPaillard commented 1 month ago

Thank you for this