0

I have newtonsoft json web api project that try to migrate system.text but I cannot figure out how to convert the code below.

    public static void SerializeJsonIntoStream(object value, Stream stream)
    {
        using (var sw = new StreamWriter(stream, new UTF8Encoding(false), 1024, true))
        using (var jtw = new JsonTextWriter(sw) { Formatting = Newtonsoft.Json.Formatting.None })
        {
            var js = new JsonSerializer();
            js.ReferenceLoopHandling = ReferenceLoopHandling.Ignore;
            js.Serialize(jtw, value);
            jtw.Flush();
        }
    }
datnet
  • 1
  • 2
    Just serialize to a stream? https://learn.microsoft.com/en-us/dotnet/api/system.text.json.jsonserializer.serialize?view=net-6.0#system-text-json-jsonserializer-serialize-1(system-io-stream-0-system-text-json-jsonserializeroptions) – davidfowl Aug 31 '22 at 15:59
  • [JsonSerializer.Serialze](https://learn.microsoft.com/en-us/dotnet/api/system.text.json.jsonserializer.serialize?view=net-6.0) has overloads that write to a stream – Panagiotis Kanavos Aug 31 '22 at 16:08
  • 2
    @davidfowl haven't seen you in a while. There are some Channel questions that could benefit from your input – Panagiotis Kanavos Aug 31 '22 at 16:11
  • Where are those questions? – davidfowl Aug 31 '22 at 21:26

0 Answers0