JSON.NET attributes and RavenDB

RavenDB becomes more and more popular among .NET developer. The simple to use C# Api makes it a good choice for many project that require a fast persistence layer.

The JSON that is stored, can be customize using JSON.NET attributes. But sometimes you annotate your data POCOs and nothing happens e.g.

  • You put [JsonIgnore] on a property but it still appears in the created JSON

The reason is simple: The RavenDB team decided to put a copy of JSON.NET in the RavenDB dll and only the attributes from this “special” namespace are used for the JSON handling. So if you want to customize the JSON in the database, always use attributes from theĀ Raven.Imports.Newtonsoft.Json namespace.

Advertisements