Skip to content

Can I serialize a JsonObject using AOT-compatible methods? #114124

Discussion options

You must be logged in to vote

JsonNode, which JsonObject inherits from, has dedicated serialization/parsing methods which do not go through generic reflection-based path:

e.g. dotnet publish /p:PublishAot=true emits no warnings for

using System.Text.Json.Nodes;

var forecastObject = new JsonObject
{
    ["Date"] = new DateTime(2019, 8, 1),
    ["Temperature"] = 25,
    ["Summary"] = "Hot",
    ["DatesAvailable"] = new JsonArray(
            new DateTime(2019, 8, 1), new DateTime(2019, 8, 2)),
    ["TemperatureRanges"] = new JsonObject
    {
        

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@fabianoriccardi
Comment options

Answer selected by fabianoriccardi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants