Skip to content

Commit

Permalink
update Json serializer
Browse files Browse the repository at this point in the history
Turns out this has better performance and less allocations
  • Loading branch information
michaelstonis committed Oct 29, 2021
1 parent dfa8fc0 commit 212ced3
Showing 1 changed file with 1 addition and 10 deletions.
11 changes: 1 addition & 10 deletions Tycho.JsonSerializer.NewtonsoftJson/NewtonsoftJsonSerializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,7 @@ public ValueTask<T> DeserializeAsync<T> (Stream stream, CancellationToken cancel

public object Serialize<T> (T obj)
{
using var stream = new MemoryStream();
using var writer = new StreamWriter(stream);
using var jsonWriter = new JsonTextWriter(writer);

_jsonSerializer.Serialize(jsonWriter, obj);

jsonWriter.Flush();
stream.Position = 0;

return stream.ToArray();
return JsonConvert.SerializeObject(obj);
}

public override string ToString () => nameof (NewtonsoftJsonSerializer);
Expand Down

0 comments on commit 212ced3

Please sign in to comment.