Implementations of the ISerialization and IBodyDeserializer interfaces, based on Jil, for Nancy. Because a little bit more Performance never hurts.
Start of by installing the Nancy.Serialization.Jil NuGet package:
PM> Install-Package Nancy.Serialization.Jil
When Nancy detects that the JilSerializer
and JilBodyDeserializer
types are available in the AppDomain of your application, it will assume you want to use them, rather than the default ones.
By default Jil's Options are set to Options.ISO8601IncludeInherited
for both, Serialization and De-Serialization. If you want to change that behaviour, choose one of the many Configuration Options available and change the Default one used like that:
// change only the JilSerializer's Options
Nancy.Serialization.Jil.JilSerializer.Options = Options.ISO8601PrettyPrintNoHashing;
// change only the JilBodyDeserializer's Options
Nancy.Serialization.Jil.JilBodyDeserializer.Options = Options.ISO8601PrettyPrintNoHashingIncludeInherited;
// or for both:
Nancy.Serialization.Jil.JilSerializer.Options = Nancy.Serialization.Jil.JilBodyDeserializer.Options = Options.ISO8601PrettyPrintNoHashing; // that's usually what you'd like I guess
Jil, by default, does not (serialize) nested object graphs and ignores inheritance and its structure (Json.Net however does). In order to get the same behaviour, the default Options have been switched from Options.Default
to Options.ISO8601IncludeInherited
(see kevin-montrose/Jil#71 over at Jil's repository for details). If you don't want or need inherited members to be serialized, you can easily switch this back following the instructions above.
As this library is based on Jil, all its Features but also Limitations also apply here: .Net >= 4.5 is required, but even more so please take a close look at its List of supported types and how to configure and tailor Jil to your specific environment and use case. However, one thing I've noticed is that Jil seems to require a public, empty .ctor for the types to be deserialized. Keep that in mind when designing your DTOs.
As I haven't used Nancy.Serialization.JsonNet myself, I cannot say much about Nancy.Serialization.Jil's being a simple drop-in replacement, but Jil's Default set of options (see above) does come with a differen Json notation compared to Json.Net when it comes to Property-Names. When porting the tests over, I noticed the original json test fixtures ones had property names like .someProperty (even though the classes propery names were in fact .SomeProperty). Jil on the other hand keeps these properties at their original case, meaning a property named .SomeProperty remains SomeProperty inside the serialized Json.
This is basically a port of Nancy.Serialization.JsonNet but replacing the Json.NET specific parts with Jil's ones and adjusting the test correspondingly. So thanks to Andreas Håkansson, Steven Robbins and the other original contributors.
Moreover thanks alot to Kevin for his awesome work on Jil.
Copyright © 2016 Jörg Battermann
Nancy.Serialization.Jil is licensed under MIT. Refer to LICENSE.md for more information.