NancyFx / Nancy.Serialization.JsonNet

NewtonSoft.Json serializer for Nancy
MIT License
40 stars 32 forks source link

Must register ISerializer in container #40

Closed dstj closed 8 years ago

dstj commented 8 years ago

Hi, a small issue,

In order to use Nancy.Serialization.JsonNet with Nancy 1.4.3, I had to manually register the ISerializer and the CustomJsonSerializer, otherwise the custom serializer would not be used.

container.Register<ISerializer, JsonNetSerializer>();
container.Register<JsonSerializer, CustomJsonSerializer>();

The home page doc states that we only need to register the customer serializer.

Thanks.

mvacha commented 8 years ago

I had the same issue. Unless I explicitly specify the JsonNetSerializer in bootstrapper, it wouldn't be used, because the assembly reference gets removed at compile time. As mentioned in: https://github.com/NancyFx/Nancy/wiki/Bootstrapper.

ChangePlaces commented 8 years ago

Can confirm the problem and that this solves it!

sakopov commented 8 years ago

Adding an explicit registration for ISerializer still doesn't apply custom json serializer. Not only that, it also looses default json serializer settings since i'm seeing default camel casing no longer being applied.

thecodejunkie commented 8 years ago

I just created a sample using

And it is picking up JsonNetSerializer just fine. In order to customize the behavior, of the serializer, explicitly register your JsonSerializer, in ConfigureApplicationContainer after you've call base.ConfigureApplicationContainer(). See https://github.com/NancyFx/Nancy.Serialization.JsonNet/issues/44#issuecomment-263029952 for a functioning sample.