-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Serialisation/parsing of custom structures in JSON (#60)
This patch adds traits for types to describe how they can be serialised and reified when using a JSON encoding. The approach here favours control over reification to avoid issues with arbitrary code being able to construct capability-bearing types by simply stating their names; here the person describing the JSON types must provide a mapping for them that describes the lowering and the reification passes. In order to support custom serialisation, the package forks JSON into standard JSON (`json` object), and "extended" JSON (`extended-json`) object. The extended JSON object stores non-standard types as the dictionary `{"@type": "unique-tag", "value": ... }`, it then uses the mapping contained in the extended JSON type to both serialise and reify these types. Moving the extended JSON portion to a separate type avoids issues with JSON payloads that may use this convention in a different way, and also discourages a single object with all mappings. Example usage: ``` let My-domain = #json-serialisation bare | tag: "project" type: #project | tag: "package" type: #pkg; let Json = #extended-json with-serialisation: My-domain; assert (Json parse: (Json serialise: new project("title", new pkg("name", "filename")))) === new project("title", new pkg("name", "filename")); ```
- Loading branch information
1 parent
166d09c
commit ea3770f
Showing
11 changed files
with
549 additions
and
141 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
% crochet | ||
|
||
singleton internal; | ||
capability internal; | ||
|
||
protect type internal with internal; | ||
protect global internal with internal; |
Oops, something went wrong.