Can I serialize a JsonObject using AOT-compatible methods? #114124
Answered
by
neon-sunset
fabianoriccardi
asked this question in
Q&A
-
As reported in the title, can I serialize a JsonObject (edited dynamically) and being compatible with AOT?
But the third line gives the following 2 warnings:
I'm using .NET9. |
Beta Was this translation helpful? Give feedback.
Answered by
neon-sunset
Apr 2, 2025
Replies: 1 comment 1 reply
-
e.g. 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
{
["Cold"] = new JsonObject
{
["High"] = 20,
["Low"] = -10
}
},
["SummaryWords"] = new JsonArray("Cool", "Windy", "Humid")
};
Console.WriteLine(forecastObject.ToJsonString()); |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
fabianoriccardi
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
JsonNode
, whichJsonObject
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