Switch to JSON Object vs JSON Array based encoding of Attributes. #132
Replies: 1 comment
-
Thanks for the detailed proposal. I think the "decorations" feature that we are actively working on will achieve this with some tweaks. Before I get into that though let me clear up a misunderstanding:
Everything in Morphir including the IR, the attributes on the IR, test cases and decorations (in preview for now) use the same JSON serialization standard documented here: https://github.com/finos/morphir-elm/blob/main/docs/developers-guide/files/json-schema-mappings.md The standard happens to map Unit to In regards to your proposal, I think we are aiming to achieve the same thing with slightly different data structures. What you are proposing seems to look like this (I'll assume Attribute and Decoration means the same thing and will use Attribute to make it easier to follow): type alias StorageFormat =
IR (Dict AttributeID AttributeShape) What we are proposing with Decorations is this: type alias StorageFormat =
( IR, Dict AttributeID (Dict NodeID AttributeShape) ) As you can see, they are not all that different, it's just organized differently. What's common is that:
There are also a few differences between Attributes and Decorations:
There's probably other things to consider but I think it will be easier to discuss all this with the Decoration spec in hand. We should have an initial version of that available by next week. |
Beta Was this translation helpful? Give feedback.
-
I'll start off by saying I understand there is work on "decorators" happening, but I want to talk about an alternative.
Currently attributes are encoded in a very custom way.
Attributes for type nodes in
morphir-ir.json
are always encoded as Unit ({}
), while attribute nodes for value nodes are encoded as a JSON array.I feel like the reason we even need decorators is because of choosing this custom encoding.
I think users would be able to much more easily add their custom attributes to
morphir-ir.json
if attributes were always encoded as JSON objects.In order to have a custom annotation we add a JSON Object into the attributes slot when encoding a node (i.e. value node).
That JSON object as all JSON Objects contains key value pairs.
The key would could one of the following (by this I mean we choose one of these not that we support all):
"Morphir.Attributes.TypeAnnotation"
"Morphir.SDK:Attributes:TypeAnnotation"
JSON-LD
type of encodingThe value portion would be encoded as a JSON Value (meaning it could be any of the standard JSON values).
From the Morphir standpoint Morphir could/would provide some standard things, such as Type Annotations which are currently encoded in the attributes slot of Morphir value nodes today.
This means the following:
Encoding Nulls
Nulls continue to encode as:
Encoding Type Annotations
Encoding with Custom Attributes/Annotations
Benefits of the above is that:
Downsides:
I'm sure there are other upsides and downsides.
Thoughts?
Beta Was this translation helpful? Give feedback.
All reactions