-
Notifications
You must be signed in to change notification settings - Fork 133
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
Json Serialiser doesn't handle structs well and ignores type converters #622
Comments
Even for the records, this doesn't work: public readonly partial record struct ProductId
{
public System.Guid Value { get; }
public ProductId(System.Guid value)
{
Value = value;
}
} But this does work: public readonly partial record struct ProductId(Guid Value) {} |
Interestingly, it works if I use |
Hi, sorry for the late reply...
You could try to insert your custom converter at the beginning of the converters list (like here), this had to be done for the |
@rose-a Thanks for the suggestion! But I still think that it is a bug because annotating the type with
doesn't work. But it does work for the |
Yeah, I'd expect that to work, too. But I don't know how to fine-tune the System.Text.Json serializer for that... PRs welcome 😉 |
@rose-a I may try to find some time to look into it... If the type is marked with Also, could you please elaborate on the |
If I remember correctly it is needed for deserialization of anonymous types... If you're playing around, you could check what happens if you remove it (some tests should fail)
Sounds reasonable, although I have no idea on how this will impact performance... @sungam3r @Shane32 do you have an opinion on this? |
Yeah, that's the thing. I tried commenting out this line and even removing the whole Hence the question: why do we need it? |
Hm... trying to read up on this, it seems like this might have become obsolete wit .NET 5.0... |
If so, then it may fix the issue in a nicest way: fixing bugs by removing code :) |
@AlexeyRaga Could you please post a complete combination of class/struct and JsonConverter which shows the described behavior? |
Hello,
I have some wrapper types that I want to use with GraphQL, which look like this:
I also provide
JsonConverters
for these types, which look similar to:I register the converters in the client:
But when deserialising the GraphQL response I get this error:
I do not quite understand why
ImmutableConverter
was chosen and not the specific one that I registered...I validated the approach, and it works if I create my wrapper types as
record
s somehow:But the goal is to make it work with plain structs and have libraries like https://github.com/lucasteles/Strongly to generate wrapper types, Json converters, and all the required boilerplate around them.
I believe that fixing the "plain structs" misbehavior would allow it to work rather smoothly.
The text was updated successfully, but these errors were encountered: