Skip to content
This repository has been archived by the owner on Apr 26, 2020. It is now read-only.

NancyFx/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>();
    }
}

Code of Conduct

This project has adopted the code of conduct defined by the Contributor Covenant to clarify expected behavior in our community. For more information see the .NET Foundation Code of Conduct.

Contribution License Agreement

Contributing to Nancy requires you to sign a contribution license agreement (CLA) for anything other than a trivial change. By signing the contribution license agreement, the community is free to use your contribution to .NET Foundation projects.

.NET Foundation

This project is supported by the .NET Foundation.

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