Is the Json.NET JsonSerializer threadsafe?

后端 未结 4 869
孤城傲影
孤城傲影 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:59

    If you don't use references, JsonSerializer is thread-safe. There are however a few issues when using references in a multi-threaded context.

    First, there is a bug in the default ReferenceResolver that may cause duplicate reference id's to be used. See the GitHub issue here.

    Secondly, when reusing a JsonSerializer the default ReferenceResolver is stateful so that if you use references your reference ids will continue to increment with each serialization call you make instead of starting at 1 for each. I created a GitHub issue to address this problem here.

提交回复
热议问题