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

Question: how to apply deserialize_struct_case_insensitive to a struct? #7

Open
jlgerber opened this issue Jul 27, 2020 · 7 comments
Open

Comments

@jlgerber
Copy link

I am a bit confused by deserialize_struct_case_insensitive. It is categorized as a container_attribute in serde-aux's docs. However, the example seems to show it used as a field attribute. If it is a container_attribute, should I be able to do something like this?

#[derive(PartialEq, Eq, PartialOrd, Ord, Deserialize)]
#[serde(deserialize_with = "deserialize_struct_case_insensitive")]
pub struct Manifest {
    name: String,
    version: String,
}
@iddm
Copy link
Owner

iddm commented Jul 27, 2020

Hi @jlgerber ! Yes, the name is, unfortunately, confusing, I had plans to reorganise everything differently, but it is still yet to happen. And your thoughts are absolutely logical and correct and I apologise for having named it that way.

I'll see, perhaps, it is possible to rewrite it so that it can indeed be applied to a struct.

@jlgerber
Copy link
Author

Thank you for the prompt reply.

Fortunately, I realized that i only really had to support keys with first letters capitalized so i used aliases.

@iddm
Copy link
Owner

iddm commented Jul 29, 2020

You have still made a reasonable point. As I have wanted for so long to fix this, I now have another good reason for that. So, I'll close it and let you know once I do that.

Thank you for reaching out and contributing!

@0cv
Copy link

0cv commented Mar 19, 2023

@vityafx - do you have any updates?

It seems to me that deserialize_with is a field only attribute, but it doesn't apply to the field itself, but to the struct of that field (assuming the field has a struct type).

I'm not sure how this would be possible to apply this to the parent struct

EDIT: arguably, using flatten, such as #[serde(flatten, deserialize_with = "deserialize_struct_case_insensitive")] could do the trick, but it's just a bit awkward having to declare an additional struct, then using flatten ...

@iddm
Copy link
Owner

iddm commented Mar 20, 2023

It seems to me that deserialize_with is a field only attribute, but it doesn't apply to the field itself, but to the struct of that field (assuming the field has a struct type).
That is correct.

I'm not sure how this would be possible to apply this to the parent struct
I can't think of any way for this to happen.

I agree with the flatten thing. Unfortunately, there will be no other way possible for this, I think, with how the serde crate is written and what it allows to do.

What kind of an update were you looking for? Just renaming/reorganisation of the crate's content or, perhaps, anything else?

@0cv
Copy link

0cv commented Mar 20, 2023

You had written before:

You have still made a reasonable point. As I have wanted for so long to fix this, I now have another good reason for that. So, I'll close it and let you know once I do that.

And I was hopeful, that maybe you had found a way to avoid using a nested struct. Or maybe your comment applied to clarifying the usage?

@iddm
Copy link
Owner

iddm commented Mar 20, 2023

You had written before:

You have still made a reasonable point. As I have wanted for so long to fix this, I now have another good reason for that. So, I'll close it and let you know once I do that.

And I was hopeful, that maybe you had found a way to avoid using a nested struct. Or maybe your comment applied to clarifying the usage?

Yes, so unfortunately it was more, if not only, clarifying the situation and the absence of a good workaround.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants