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

Is Newtonsoft Support Within Consideration/Scope? #56

Closed
noah-integrityinspired opened this issue Jun 19, 2023 · 3 comments
Closed

Is Newtonsoft Support Within Consideration/Scope? #56

noah-integrityinspired opened this issue Jun 19, 2023 · 3 comments
Labels
enhancement New feature or request

Comments

@noah-integrityinspired
Copy link

noah-integrityinspired commented Jun 19, 2023

Is your feature request related to a problem? Please describe.
I am working with an ASP.NET project that is using newtonsoft for serialization for controllers. However the code generated by ZeroQL is built for System.Text.Json (e.g. the JsonPropertyName attributes). Apologies if this is already possible; my check of the documentation and thumbing through of GenerateCommand.cs did not yield results.

Like all projects, this one has to decide what is within scope and out of scope; and so I wanted to see if Newtonsoft support was within scope of ZeroQL

Describe the solution you'd like
For usage, the simplest approach I could think of is some option on generate command to configure using Newtonsoft vs System.Text.Json. Maybe some sort of flag like --serializer="Newtonsoft" vs --seralizer="System.Text.Json", with it defaulting to System.Text.Json if the flag is not specified. (and a similar approach for the zeroql.json file)

Describe alternatives you've considered
I am trying to configure the ASP.NET project to use one serializer or another depending on the controller; this appears to be possible but also appears to be very difficult - I've yet to get it to work. Other alternatives are being considered but they all feel quite clunky and undesirable.

Additional context
This is very much asked in the spirit of "if you never ask, the answer is always no". If this support is not within consideration at this time, no worries!

@noah-integrityinspired noah-integrityinspired added the enhancement New feature or request label Jun 19, 2023
@byme8
Copy link
Owner

byme8 commented Jun 20, 2023

I was thinking about it initially but decided there was no point in it. System.Json is faster and already "installed" in net6.0+ projects. To make it work, it is not enough to replace the attribute. You have to rewrite the custom serializes for scalar and supported built-in types. Incorporate new options into the source generator. Figured out how to cover all scenarios in the integration tests. I would say a big chunk of work.

What raises the question of what benefits it would bring? Performance? No. Ease of use? They are pretty much the same in most scenarios. Compatibility? System.Text.Json works on netstandard. The only thing I can see is eliminating the dependency on System.Text.Json, which can be useful for projects already using Newtosoft. At the same time, the best path forward is to use a built-in serializer. So, from my perspective, there is no point to invest time in it.

@byme8
Copy link
Owner

byme8 commented Jun 20, 2023

I am trying to configure the ASP.NET project to use one serializer or another depending on the controller

I don't get it. Why would you need to configure anything to work with the ZeroQL client? Everything happens under the hood and doesn't require any intervention from the developer side.

@noah-integrityinspired
Copy link
Author

I don't get it. Why would you need to configure anything to work with the ZeroQL client? Everything happens under the hood and doesn't require any intervention from the developer side.

Oh totally agree with you; getting the data from the ZeroQL client works like a charm. This is for when I am trying to return a ZeroQL model out of the controller. For example:

public async Task<IActionResult> Get()
{
  var response = await GQLClient.Query(...)
  return Ok(response.Data)
}

Which works just fine when I remove the .AddNewtonsoftJson() when the asp.net up is spun up. But the project needs that since a lot of the controllers in the project were designed for NewtonsoftJson serialization. When I keep the .AddNewtonsoftJson() code, it still returns the data but serializes the backing fields (so there are '__' for all the sub objects)

Hence my attempts to configure which controllers used which serializers. Thankfully I found another approach that works for my situation.


So, from my perspective, there is no point to invest time in it.

Got yeah! I appreciate you taking the time to read and share your thoughts.

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

No branches or pull requests

2 participants