Giter Club home page Giter Club logo

Comments (11)

AlexeyRaga avatar AlexeyRaga commented on June 24, 2024

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) {}

from graphql-client.

AlexeyRaga avatar AlexeyRaga commented on June 24, 2024

Interestingly, it works if I use Newtonsoft.Json but not System.Text.Json

from graphql-client.

rose-a avatar rose-a commented on June 24, 2024

Hi, sorry for the late reply...

I do not quite understand why ImmutableConverter was chosen and not the specific one that I registered...

You could try to insert your custom converter at the beginning of the converters list (like here), this had to be done for the ErrorPathConverter and MapConverter, too.

from graphql-client.

AlexeyRaga avatar AlexeyRaga commented on June 24, 2024

@rose-a Thanks for the suggestion!
Indeed, it works with the insert method!

But I still think that it is a bug because annotating the type with

[System.Text.Json.Serialization.JsonConverter(typeof(ProductIdSystemTextJsonConverter))]

doesn't work.

But it does work for the Newtonsoft serialiser. So, something is still odd here.

from graphql-client.

rose-a avatar rose-a commented on June 24, 2024

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 ๐Ÿ˜‰

from graphql-client.

AlexeyRaga avatar AlexeyRaga commented on June 24, 2024

@rose-a I may try to find some time to look into it...
As a super quick and easy fix, would you accept this logic?

If the type is marked with JsonConverterAttribute (there is a converter for this type), ImmutableConverter should return false from CanConvert so that the registered converter can have its turn.

Also, could you please elaborate on the ImmutableConverter, why is it needed?

from graphql-client.

rose-a avatar rose-a commented on June 24, 2024

Also, could you please elaborate on the ImmutableConverter, why is it needed?

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)

If the type is marked with JsonConverterAttribute (there is a converter for this type), ImmutableConverter should return false from CanConvert so that the registered converter can have its turn.

Sounds reasonable, although I have no idea on how this will impact performance... @sungam3r @Shane32 do you have an opinion on this?

from graphql-client.

AlexeyRaga avatar AlexeyRaga commented on June 24, 2024

If you're playing around, you could check what happens if you remove it (some tests should fail)

Yeah, that's the thing.
I already checked it out, all the tests still pass if we remove ImmutableConverter.

I tried commenting out this line

https://github.com/graphql-dotnet/graphql-client/blob/master/src/GraphQL.Client.Serializer.SystemTextJson/JsonSerializerOptionsExtensions.cs#L9

and even removing the whole ImmutableConverter.cs file, all the tests are happy.

Hence the question: why do we need it?

from graphql-client.

rose-a avatar rose-a commented on June 24, 2024

Hm... trying to read up on this, it seems like this might have become obsolete wit .NET 5.0...

from graphql-client.

AlexeyRaga avatar AlexeyRaga commented on June 24, 2024

If so, then it may fix the issue in a nicest way: fixing bugs by removing code :)

from graphql-client.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.