Skip to content

cemremengu/Nancy.Serialization.JsonNet

 
 

Repository files navigation

Implementations of the ISerialization and IBodyDeserializer interfaces, based on Json.NET, for Nancy

Usage

Start of by installing the Nancy.Serialization.JsonNet nuget

When Nancy detects that the JsonNetSerializer and JsonNetBodyDeserializer types are available in the AppDomain, of your application, it will assume you want to use them, rather than the default ones.

Customization

If you want to customize the behavior of Json.NET, you can provide your own implementation of the JsonSerializer type. For example, the following implementation configures Json.NET to use camel-casing and to indent the output

public class CustomJsonSerializer : JsonSerializer
{
    public CustomJsonSerializer()
    {
        this.ContractResolver = new CamelCasePropertyNamesContractResolver();
        this.Formatting = Formatting.Indented;
    }
}

In order for Nancy to know that you want to use the new configuration, you need to register it in your bootstrapper. Here is an example of how you would do that using the DefaultNancyBootstrapper

public class Bootstrapper : DefaultNancyBootstrapper
{
    protected override void ConfigureApplicationContainer(TinyIoCContainer container)
    {
        base.ConfigureApplicationContainer(container);

        container.Register<JsonSerializer, CustomJsonSerializer>();
    }
}

Copyright

Copyright © 2010 Andreas Håkansson, Steven Robbins and contributors

License

Nancy.Serialization.JsonNet is licensed under MIT. Refer to license.txt for more information.

About

NewtonSoft.Json serializer for Nancy

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • C# 69.7%
  • Ruby 30.3%