-
-
Notifications
You must be signed in to change notification settings - Fork 693
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
Support System.Text.Json (as well as Newtonsoft.Json) #839
Comments
Ignoring Default ValuesAs @tuscen pointed out on #838, default value of the value types should be ignored during serialization but it's not supported at the moment. Default class Foo
{
[JsonPropertyName("field_bar")]
public bool FieldBar { get; set; }
[JsonPropertyName("field_baz")]
public string FieldBaz { get; set; }
} [Fact]
public void Test()
{
var opts = new JsonSerializerOptions { IgnoreNullValues = true };
string json = JsonSerializer.Serialize(new Foo(), opts);
// JSON is {"field_bar":false}
// assertion fails
Assert.Equal("{}", json);
} see more at dotnet/corefx#40922 |
@tuscen :
|
|
@dumkin unfortunately this is not a solution because if someone would use the library with a webhook they could need different json options compared to what we need. And as far as I know json options are global in ASP.NET Core. |
I don't really understand at all why it is necessary to create a controller with an action with parameters. Why not just ask to add an additional route. And get everything you need from the body. And here it doesn't matter. use system.text.json or newtonsoft.json. it will not affect other libraries and user code |
It's just that now, in essence, the situation is the same. Only the other way around. now it is required
Which forces us to use NewtonsoftJson exactly as globally |
You have a point 🤔 We'll think about it. |
This is something I would very much like in this library. Is there anything I can help with that would get this done quicker? |
@sixpeteunder Unfortunately , there's not much you can do. We rely heavily on:
All these features are still missing even in .NET 6. Basically STJ is still mostly in MVP stage and is usable for APIs you control completely |
I think things are changed in .net 8 |
This would be really great to have, it is a blocker for AOT. |
Well, usage in Unity or front end blazor is strongly not recommended, so its not big of a deal ) |
True, but AOT is not just about raw performance but also about memory footprint. Especially trimming is really great to reduce memory footprint. I'm experimenting with TelegramBot client used for forex trading running on very low spec VPS provided by my forex broker. It has just 1GB RAM available and it has to run MT4 platform + my telegram bot. Currently it works, but sometimes I'm getting near the memory limit. |
Whats the status on this? looks like there is a lot of problems to migrate |
@luizfbicalho All the changes are in the branch tuscen/stj-2 and I'd say it's 80-90% ready. I just don't have enough free time to squash all the bugs and finish it. I want to release Bot API 7.0 and 7.1 updates first and then release STJ support. The thing is that it ended up quite non-trivial in a lot of places and it probably won't be backwards compatible so it'll be released as a new major version. The current plan is to completely remove Newtonsoft from |
I have the same issues with my projects, thanks for the answer and I'll see it if I can help in any way |
Also the first release with STJ will not be AOT compatible. I want to implement it in a separate release, because otherwise it will take too much time. |
@luizfbicalho you can run unit tests from that branch and see which ones are failing. We also will need to add a few hundreds of serialization tests more to ensure that everything works as expected :) |
switch to STJ has been done. issue #1322 will track AOT compatibility |
We can use new and high performance JSON serialization
System.Text.Json
package. Faster serialization/deserialization of request and response data structures is the main reason for this suggestion.There are a few things to consider:
System.Text.Json
requires .NET Standard 2.0 and that's .NET 4.6.1+.Snake case naming policy support won't come until .NET 5 (see dotnet/corefx#41354). Alternatives are using camel cased naming policy by default, e.g. for
username
, and overriding specific fields, e.g. forfirst_name
, with the[JsonPropertyName("first_name")]
.Custom type converters such as for
DateTime
to Unix epoch time need to be implemented. This is very similar to the current implementation forNewtonsoft.Json
.References
The future of JSON in .NET Core 3.0
The text was updated successfully, but these errors were encountered: