Closed xmedeko closed 8 years ago
Isn't this a duplicate of #36?
No it's not a duplicate. These are two different problems.
How are these two different problems? By your description it seems to be exactly the same. It's picking the wrong serializer?
The #36 is that the formatter.Serializer
has different order depending on the machine/environment.
This bug is about wrong caching of FormatterExtensions.jsonSerializer
on the same machine/environment.
"wrong caching"? I'm very confused :confused:
Look at the FormatterExtensions.AsJson
code:
var serializer = jsonSerializer ?? (jsonSerializer = formatter.Serializers.FirstOrDefault(s => s.CanSerialize("application/json")));
It takes the first JSON serializer from the formatter from the first call and caches it in the jsonSerializer
. So, when the next call has different formatters, it still uses the one from jsonSerializer
.
How can the next call have "different formatters"? The container configuration is set up once. It won't change at runtime.
Ask the Nancy Diagnostics author. It's either a bug of the FormatterExtensions.jsonSerializer
or the Nancy.Diagnostics
.
Note: IMO FormatterExtensions.AsJson
has the IResponseFormatter
parameter and should work well with all IResponseFormatter
objects, even if I create my own IResponseFormatter
independent of the container configuration.
Ask the Nancy Diagnostics author. It's either a bug of the FormatterExtensions.jsonSerializer or the Nancy.Diagnostics.
Either way, this issue has nothing to do with the Newtonsoft.Json serializer :smile:
Note: IMO
FormatterExtensions.AsJson
has theIResponseFormatter
parameter and should work well with allIResponseFormatter
objects, even if I create my ownIResponseFormatter
independent of the container configuration.
It doesn't?
OK, created https://github.com/NancyFx/Nancy/issues/2399
I have Nancy 1.4.3, Nancy.Serialization.JsonNet 1.4.1. When start my app with Nancy diagnostics and go first to the
http://localhost:8080/_Nancy/interactive#Testing%20Diagnostic%20Provider
and then run my request, the request is formatted by theDefaultJsonSerializer
and notJsonNetSerializer
since theFormatterExtensions.jsonSerializer
keeps theDefaultJsonSerializer
from the first request.I guess both
jsonSerializer
andxmlSerializer
fields should be removed.