-
-
Notifications
You must be signed in to change notification settings - Fork 21
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
Add helpers to deserialise JSON-LD in a more robust way #492
Conversation
Thanks for the thorough PR! Will have a look at it |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is just a small surface level overview I had. I have to read a bit more into serde
to give a final review.
I know about some of the concepts (like DeserializeSeed
, which is essentially just deserialization that allows to pass state) but I gotta refresh on them..
Per review comment at: <kitsune-soc#492 (comment)>. Co-Authored-By: Aumetra Weisman <aumetra@cryptolab.net>
Yeah the docs explain that much, but the seeds in the patch don't really have any runtime state. Rather, the helpers in the patch view the seed as a sort of callback, which might be a twist to the docs' view. |
As a next step, we may want to make the model types accept unknown extension types in But that looks like an Activity Streams-specific logic rather than the general JSON-LD logic which the patch aims to focus on, and that would also involve less trivial design decisions1, so I think it's better to leave it off in the patch. Footnotes
|
Yeah, as a next step for immediate fixing of these issues, we should just type out an alternative field in those enums declared with |
A: MapAccess<'de>, | ||
{ | ||
#[derive(Deserialize)] | ||
#[serde(field_identifier, rename_all = "camelCase")] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not a review, just noting: Wow, this is really just an undocumented functionality, huh?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I grasped enough of the code to give this an okay
This patch implements some helper functions to translate JSON-LD data structures to something easier to deserialise as Rust data structures, and applies them to the types in
kitsune_type::ap
using the#[serde(deserialize_with = "…")]
attribute.This also replaces some usage of the
#[serde(untagged)]
helper types (which basically works by deserialising the full input to a DOM and tries to deserialise it to the variants one by one until succeeds) with the new helpers.Admittedly, the hand-written
DeserializeSeed
implementations are full of boilerplates (as they generally tend to; Serde's builtin implementations are similarly verbose, for instance), with ~5x more lines of code than Mitra'sdeserialization.rs
. Yet I think they're reasonably modular and maybe efficient (no benchmarks though!).In case you're not familiar with it, think of an
impl DeserializeSeed
value as a closure-version of the genericDeserialize::deserialize
function. Using the trait allows composing thedeserialize
functions in a higher order function-like manner. The patch takes advantage of it to compose theFirstId
helper from theId
andFirst
helpers, and theIdSet
helper from theId
andSet
helpers.Closes #489.