-
-
Notifications
You must be signed in to change notification settings - Fork 198
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
Use System.Text.Json as the default serializer #504
Conversation
Just for info, in a recent PR I had to work with |
One issue will be with polymorphism. For instance if we have a list of content parts, each type needs to be allow-listed with a custom string as a type discriminator. This can be done on the base type so it doesn't work for us. Fortunately there is a code first way. This might mean that we would have to use the existing I have been warned that |
Okay, would need more time. For info I saw that JsonDocument is disposable, for example it rents some data. |
The most dificult one, is a Currently this also causes problems if a serialized type is no longer available, as it's been moved / renamed / changed (has happened a lot for us, as we right a lot of custom steps etc), because it throws an exception deep in YesSql/Serialization, and the only fix is to start editing the sql table, to fix the types, which is quite frankly a PITA. I would suggest, that a registration arrangement for things like |
I already planned to do it after an old PR that has been closed #237 @sebastienros if you don't mind I can push some commits here as long as I'm working on related STJ in OC |
@deanmarcussen good point to content parts. I wanted to make a point and used the wrong example ;) Dean to the rescue. Though I am fine with migrations updating json documents when we do actual breaking changes. One thing that STJ adds is that we can set the value for the type discriminator value. Like instead of storing the fullname we could just store a number or a simple class name. Also with DeploymentSteps removed we can implement some custom converters that would handle that, there are samples for that. It would be a good idea to go over all the documents of a live database to find where |
Polymorphism is cool, didn't know about this I started some tests locally, first problem is the missing I will continue but by using net8.0 because they introduced As I can see we are also missing some options, for example when merging arrays. Hope I will have time to continue ;) |
I did some experimental in OC, I created an extensions to merge, the complex part are objects and arrays
Right |
@sebastienros rebated and fixed the conflict. Is there more work to be done on this PR or is it something that can be merged? |
@sebastienros skipped the .NET 7 and onto .NET 8. |
return i; | ||
if (reader.TryGetInt64(out var l)) | ||
return l; | ||
// BigInteger could be added here. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was not sure that we need something here for BigInteger
, but maybe if it fails to convert for example to a long because of the dedicated max/min values.
But we may also need to provide a JsonBigIntegerConverter
, for info I found this one here https://github.com/graphql-dotnet/graphql-dotnet/blob/d46bde6d5e30ea1e3a314f40a408f9c86480018d/src/GraphQL.SystemTextJson/JsonConverterBigInteger.cs#L14 in which they define a TryGetBigInteger()
that takes care if the reader has more than one segment.
public static bool TryGetBigInteger(ref Utf8JsonReader reader, out BigInteger bi)
{
var byteSpan = reader.HasValueSequence ? reader.ValueSequence.ToArray() : reader.ValueSpan;
Span<char> chars = stackalloc char[byteSpan.Length];
Encoding.UTF8.GetChars(reader.ValueSpan, chars);
return BigInteger.TryParse(chars, NumberStyles.Integer, NumberFormatInfo.InvariantInfo, out bi);
}
@sebastienros Just for info So in OrchardCMS/OrchardCore#14572 I'm using a clone of your This converter fixed issues in the context of
This converter also checks for
|
Merging this into release/5.0 |
Co-authored-by: Sébastien Ros <[email protected]>
Fixes #227