Created
September 10, 2014 06:25
-
-
Save bernos/c3774ca1902fc4ee7035 to your computer and use it in GitHub Desktop.
Nancyfx Json Serializer configuration
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Nancy; | |
using Nancy.Bootstrapper; | |
using Nancy.Serialization.JsonNet; | |
using Newtonsoft.Json; | |
using Newtonsoft.Json.Serialization; | |
using System.Collections.Generic; | |
using System.Collections.ObjectModel; | |
namespace Templify.NancyAspNetRazor.Web.Config | |
{ | |
public class JsonSerializerConfiguration : IRegistrations | |
{ | |
private readonly ICollection<TypeRegistration> _typeRegistrations; | |
public JsonSerializerConfiguration() | |
{ | |
_typeRegistrations = new Collection<TypeRegistration> | |
{ | |
new TypeRegistration(typeof(ISerializer), typeof(CustomJsonSerializer), Lifetime.Singleton) | |
}; | |
} | |
public IEnumerable<TypeRegistration> TypeRegistrations { | |
get { return _typeRegistrations; } | |
} | |
public IEnumerable<CollectionTypeRegistration> CollectionTypeRegistrations | |
{ | |
get { return null; } | |
} | |
public IEnumerable<InstanceRegistration> InstanceRegistrations | |
{ | |
get { return null; } | |
} | |
} | |
public class CustomJsonSerializer : JsonNetSerializer | |
{ | |
public CustomJsonSerializer() : base(new JsonSerializer | |
{ | |
ContractResolver = new CamelCasePropertyNamesContractResolver(), | |
DateTimeZoneHandling = DateTimeZoneHandling.Utc | |
}) | |
{ | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment