Skip to content
This repository has been archived by the owner on Nov 5, 2021. It is now read-only.

joergbattermann/Nancy.Serialization.Jil

Repository files navigation

Nancy.Serialization.Jil NuGet Version Build status

Implementations of the ISerialization and IBodyDeserializer interfaces, based on Jil, for Nancy. Because a little bit more Performance never hurts.

Usage

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.

Customization & Jil Options

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

(De-)Serializing nested Object Graphs

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.

Limitations

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.

Changes between Nancy.Serialization.Jil and *.JsonNet

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.

Thanks

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

Copyright © 2016 Jörg Battermann

License

Nancy.Serialization.Jil is licensed under MIT. Refer to LICENSE.md for more information.

About

Provides JSON (De-)Serialization support for Nancy using Jil.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages