Skip to content
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

Fix incorrect deserialization of vectors of enums from sequences of tags #663

Merged
merged 14 commits into from
Oct 12, 2023

Conversation

Mingun
Copy link
Collaborator

@Mingun Mingun commented Oct 9, 2023

This PR fixes #567 which is an instance of generic problem, where top-level deserializer used to deserialize elements inside <tags>. It changes things in that way that correct deserializer is used to deserialize types.

The diagram below shows how each struct is related to each other in this PR (SimpleTypeDeserializer has more usages, not all of them shown in order to keep diagram small):

flowchart TD
    Deserializer --maps and structs--> ElementMapAccess
    ElementMapAccess --for $text field--> SimpleTypeDeserialzier
    ElementMapAccess --for each field--> MapValueDeserializer
    MapValueDeserializer --for sequences--> MapValueSeqAccess
    MapValueSeqAccess --DeEvent::Start--> ElementDeserializer
    MapValueSeqAccess --DeEvent::Text--> TextDeserializer
    ElementDeserializer --maps and structs--> ElementMapAccess
    TextDeserializer --> SimpleTypeDeserialzier
Loading

Most commits are prepare work, the actual fix is just one line change and yet another for consistence (and I believe also fixes some bug).

The last four commits just some cleanup work, but important because it adds documentation how deserializers work and what is their difference from each other.

Mingun and others added 14 commits October 9, 2023 18:54
Complex types should pass the same deserializer that deserializes them instead of
top-level deserializer. This commit is the first prepare step for that. It just
manually expands the `forward!` macro. In the following commits, its usefulness
will be reduced
Behavior does not changed, because all calls to `self` (which is MapValueDeserializer
or SeqItemDeserializer) in the end still passed to Deserializer, as before.

Now the only methods to fix are
- deserialize_struct
- deserialize_enum

Both erroneously forward to the top-level deserializer which have it's own specific,
that shouldn't be applied when we deserialize an XML fragment inside XML tree
This will be needed later when we split SeqItemDeserializer into two deserializers.
Just copied implementation of crate::de::var::EnumAccess and slightly tune lifetimes
In this commit the implementation of SeqItemDeserializer just copied as TextDeserializer
and SeqItemDeserializer renamed to ElementDeserializer.
…ize_tuple and deserialize_struct

of the same deserializer
failures (2):
  serde-de-seq (1):
    seq::variable_name::fixed_size::list_of_enum
  serde-issues (1):
    issue567
…type variant

The implementation of `VariantAccess::newtype_variant` should be the same as
`Deserializer::visit_newtype_struct`
@Mingun Mingun added bug serde Issues related to mapping from Rust types to XML arrays Issues related to mapping XML content onto arrays using serde labels Oct 9, 2023
Comment on lines +607 to +609
{
visitor.visit_enum(crate::de::var::EnumAccess::new(self.map.de))
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This call also incorrect, because it will use top-level deserializer for deserializing newtype variants, for example, but I leave fixing that for separate PR. We do not have tests for this situation yet, and I want to approve each change by tests that failed before and pass after the change.

@Mingun Mingun merged commit 5bed370 into tafia:master Oct 12, 2023
6 checks passed
@Mingun Mingun deleted the fix-567 branch October 12, 2023 20:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
arrays Issues related to mapping XML content onto arrays using serde bug serde Issues related to mapping from Rust types to XML
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Unexpected Event::End(...) or missing field '...'
1 participant