Is the Json.NET JsonSerializer threadsafe?

后端 未结 4 887
孤城傲影
孤城傲影 2021-01-07 16:29

I\'m trying to reduce the amount of garbage my web service generates, and I noticed that we\'re creating a new Json.NET JsonSerializer instance for each request

4条回答
  •  暗喜
    暗喜 (楼主)
    2021-01-07 16:42

    Inspecting the code it appears that the serialization and deserialization methods are threadsafe, as long as you don't change any settings on the object at the same time.

    Correct, JsonSerializer is threadsafe.

    No state is shared while serializing but if you change a setting on the JsonSerializer while in the middle of serializing an object then those will automatically be used.

提交回复
热议问题