-
Notifications
You must be signed in to change notification settings - Fork 12
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
wit/bindgen: support JSON encoding of WIT types #239
Comments
Can we move the design and task list for this to an issue? Then we can have discrete PRs that implement JSON support for different types? |
Proposal for OptionThe current proposal specifies An alternate proposal would be to specify For an {"some":"foo"} For an {"none":null} For an {"some":{"none":null}} Result
For {"ok": "some OK value"} For {"error": null} |
For |
This started in #225
Goal: JSON Serialize / Deserialize WIT Records based on WIT field names.
Progress
record
- wit/bindgen: Add JSON tag to Record structs #265list
- cm: Implement json Marshal/Unmarshal for List type #266enum
tuple
variant
result
option
resource
handle types (decide behavior)error-context
stream
future
Approach
Centralize JSON serialization in the
cm
package, keeping codegen changes to a minimum.Given a complex record type:
and filling it up:
We should serialize it to JSON as:
For comparison, this is what is produced today:
Type encoding
Whenever possible, reuse standard mappings. string -> string, u32 -> uint32, etc.
Tuple handling
Tuples are encoded as json arrays with explicit
null
s.Variant handling
Variants are encoded as json dictionaries, so they can carry the variant data.
Option handling
Options rely on explicit
null
for the "None" case.Questions
Zero Value Variants
Today they end up with
tag = 0
, this impacts de-serialization of variants. We need the ability to distinct between:var v Variant
v := NewVariantWithZeroTagValue()
v := Some(NewVariantWithZeroTagValue)
atm only the
Some()
path de-serializes correctly ( pointers ).The text was updated successfully, but these errors were encountered: