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

Investigate replacing Newtonsoft.Json with System.Text.Json #99

Open
basdijkstra opened this issue Jul 14, 2023 · 13 comments
Open

Investigate replacing Newtonsoft.Json with System.Text.Json #99

basdijkstra opened this issue Jul 14, 2023 · 13 comments
Assignees
Labels
research Further research is required

Comments

@basdijkstra
Copy link
Owner

This might be a good idea as System.Text.Json is built into .NET, whereas Newtonsoft.Json is a third party library.

Even better would be if RestAssured.Net can support both, but that would probably be more work.

See eclipse-tractusx/portal-backend#110 (comment) for the discussion that drives this issue / request.

@basdijkstra
Copy link
Owner Author

A big blocker for migrating to System.Text.Json is the lack of support for JSONPath at the moment: dotnet/runtime#31068.

This would make the kinds of verifications and extractions we do in Body() and Extract() very cumbersome, if not unusable.

@basdijkstra basdijkstra added research Further research is required and removed enhancement New feature or request labels Jul 14, 2023
@basdijkstra basdijkstra added wontfix This will not be worked on and removed research Further research is required labels Oct 5, 2023
@basdijkstra
Copy link
Owner Author

Given this comment: dotnet/runtime#31068 (comment)

I'm going to close this one for now and stick with Newtonsoft.Json for the time being.

@gregsdennis
Copy link

A big blocker for migrating to System.Text.Json is the lack of support for JSONPath at the moment: dotnet/runtime#31068.

I had posted in that issue that I have a fully-compliant (to the upcoming spec) implementation of JSON Path in JsonPath.Net. Did that not work for you?

@basdijkstra
Copy link
Owner Author

@gregsdennis thank you for the comment. I don't know if it works or didn't work, because I haven't tried JsonPath.Net. It looks promising.

What's keeping me from making the migration at the moment is that I'd still be using a third-party library, although less of it as the (de-)serialization part can be handled by System.Text.Json itself. Are there any compelling reasons for making the switch, from your perspective?

Also, is there a specific reason there's no 1.0.0 version of JsonPath.Net (yet)? Just curious.

Happy to reopen this for a while.

@basdijkstra basdijkstra reopened this Dec 16, 2023
@basdijkstra basdijkstra added research Further research is required and removed wontfix This will not be worked on labels Dec 16, 2023
@gregsdennis
Copy link

Are there any compelling reasons for making the switch, from your perspective?

Well, if you need JSON Path functionality with STJ, then it's perfect. It fully implements the pending spec.

is there a specific reason there's no 1.0.0 version of JsonPath.Net (yet)?

Yeah, the spec has been pretty much finalized, but it's not ratified into RFC status yet. Once that happens, I'll bump the library to 1.0.0.

@basdijkstra
Copy link
Owner Author

Got it, thank you. I'll have a look at it soon (probably early January) and decide whether it's worth the effort. I'd be happy to get rid of Newtonsoft.Json in favour of STJ. Not that I don't like it, but why use a third-party library when there's a built-in one doing the job?

I could even see this as a first step to full removal once STJ supports JsonPath (which at some point they'll hopefully will).

Thank you once again.

@gregsdennis
Copy link

To be honest, I'm not sure it will be included given there's a lib that supports it. Maybe. There's a lot of call for JSON Schema as well (and I have that covered 😁), but the indication from the .net team so far is external support tends to be sufficient until it isn't.

@basdijkstra
Copy link
Owner Author

Which library do you mean? Yours? Sorry about the confusion here (hey, it's a Saturday morning ;)

@gregsdennis
Copy link

Yes, I was talking about mine, but it's kinda their approach to any new functionality right now. MS needs some hefty reasoning to warrant the resources to build something like JSON Path or Schema. Just how it is right now.

@basdijkstra
Copy link
Owner Author

Gotcha. Thanks. As I said, I'll have a good look at your library and what it would take to implement it.

And thank you, too, for mentioning the JSON Schema capabilities. Not too long ago I moved from NewtonSoft.Json.Schema to NJsonSchema (because of the licensing), I'm not necessarily looking to replace that yet again, but it might be good to have fewer different sources for third-party features.

Which one of your packages would I need there? All I need is the capability to pass in a schema definition as a string or as a typed object (like here: https://github.com/basdijkstra/rest-assured-net/blob/main/RestAssured.Net.Tests/JsonSchemaValidationTests.cs) and check that the actual response in a HttpResponseMessage matches the schema.

See also #96

@gregsdennis
Copy link

gregsdennis commented Dec 16, 2023

For JSON Schema, you can use the JsonSchema.FromText() method to get a schema instance from a schema in a string... or you can define the schema type-safe-like using the builder. Here's an example.

I have full docs for all my libs at https://docs.json-everything.net. The main site (https://json-everything.net) is a playground where you can run everything in your browser (Blazor WASM).

@basdijkstra
Copy link
Owner Author

Got it, thank you very much. As I said, I'll have a look soon, in the next couple of weeks.

@gregsdennis
Copy link

Json Path is now an RFC!

https://www.rfc-editor.org/rfc/rfc9535.html

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

No branches or pull requests

2 participants