-
Notifications
You must be signed in to change notification settings - Fork 87
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
Change document metadata created
, updated
to be optional
#753
Conversation
6a2fd8c
to
d3c80ea
Compare
…-updated-optional # Conflicts: # examples/low-level-api/diff_chain.rs # examples/low-level-api/resolve_history.rs
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.
Looks good but a unit test or two for the null -> None
deserialization behaviour would be appreciated in diff_iota_document_metadata
, since that could easily break in the future with no-one noticing.
Edit: PR changelog title suggestion
Change document metadata `created`, `updated` to be optional
#[serde( | ||
skip_serializing_if = "Option::is_none", | ||
deserialize_with = "double_option", | ||
default = "Default::default" | ||
)] | ||
created: Option<DiffOption<Timestamp>>, | ||
#[serde( | ||
skip_serializing_if = "Option::is_none", | ||
deserialize_with = "double_option", | ||
default = "Default::default" | ||
)] | ||
updated: Option<DiffOption<Timestamp>>, |
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.
Nit: Default::default
is redundant for two reasons: serde(default)
calls Default::default
if unspecified, and Option
is a special case in serde
which defaults to None
regardless.
Edit: updated to just omit Default::default
rather than entirely.
#[serde( | |
skip_serializing_if = "Option::is_none", | |
deserialize_with = "double_option", | |
default = "Default::default" | |
)] | |
created: Option<DiffOption<Timestamp>>, | |
#[serde( | |
skip_serializing_if = "Option::is_none", | |
deserialize_with = "double_option", | |
default = "Default::default" | |
)] | |
updated: Option<DiffOption<Timestamp>>, | |
#[serde( | |
default, | |
deserialize_with = "deserialize_double_option_diif", | |
skip_serializing_if = "Option::is_none", | |
)] | |
created: Option<DiffOption<Timestamp>>, | |
#[serde( | |
default, | |
deserialize_with = "deserialize_double_option_diif", | |
skip_serializing_if = "Option::is_none", | |
)] | |
updated: Option<DiffOption<Timestamp>>, |
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 stand corrected. default
is required here (likely because of deserialize_with
?) but the Default::default
can be omitted.
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.
Exactly, without default
a diff message without an update to both created
and updated
will not deserialize correctly. I added a unit test for this case.
// Workaround for deserialize 'null' as `Some(DiffOption::None)` instead of `None`. | ||
fn double_option<'de, T: Diff, D>(de: D) -> Result<Option<DiffOption<T>>, D::Error> |
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.
Nit: name and comment.
// Workaround for deserialize 'null' as `Some(DiffOption::None)` instead of `None`. | |
fn double_option<'de, T: Diff, D>(de: D) -> Result<Option<DiffOption<T>>, D::Error> | |
// Workaround for deserializing 'null' as `Some(DiffOption::None)` instead of `None`, | |
// otherwise it's impossible to unset the option. Only works if `Option::None` is | |
// skipped during serialization. | |
fn deserialize_double_option_diif<'de, T: Diff, D>(de: D) -> Result<Option<DiffOption<T>>, D::Error> |
created
, updated
optionalcreated
, updated
to be optional
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.
Looks good to me.
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.
Looks good to me, thanks for the changes.
Co-authored-by: Craig Bester <craig.bester@iota.org>
Description of change
Make the created and updated timestamps in the DID Document Metadata optional fields.
Links to any relevant issues
fixes issue #731
Type of change
Add an
x
to the boxes that are relevant to your changes.