JsonIgnoreAttribute

315 views
Skip to first unread message

Simon

unread,
Jul 13, 2012, 1:54:24 PM7/13/12
to rav...@googlegroups.com
Now that RavenDB 1.2 has Json.NET embedded, it'd be nice if either:
  • JsonIgnoreAttribute is renamed to RavenIgnoreAttribute
  • or  JsonIgnoreAttribute is no longer made sealed, so we can inherit from it ourselves
I have a web application which has classes, that I a) store in Raven, and b) serialize to JSON (using Json.Net) and return in response to HTTP requests that my web application receives.

My class has some properties that I'd like Raven to ignore, and other properties which I'd like Json.NET to ignore. An example:

public class Document
{
// Property to be ignored by Raven

[Raven.Imports.Newtonsoft.Json.JsonIgnore]
public string Property1 { get; set; }

//Property to be ignored by Json.NET

[Newtonsoft.Json.JsonIgnore]
public string Property2 { get; set; }
}

Ideally, this is how I'd like the attributes to be named:

public class Document
{
// Property to be ignored by Raven

[RavenIgnore]
public string Property1 { get; set; }

//Property to be ignored by Json.NET

[JsonIgnore]
public string Property2 { get; set; }
}

Ryan Heath

unread,
Jul 13, 2012, 2:11:32 PM7/13/12
to rav...@googlegroups.com
You could do it with the using keyword. 
using JsonIgnoreAttribute = Newtonsoft.Json.JsonIgnoreAttribute;
using RavenIgnoreAttribute = Raven.Imports.Newtonsoft.Json.JsonIgnoreAttribute; 

HTH
// Ryan

Oren Eini (Ayende Rahien)

unread,
Jul 15, 2012, 3:59:25 AM7/15/12
to rav...@googlegroups.com
I hesitate to make any additional changes in json.net, as that would make future merges harder.
I think that this is a good solution.

Justin A

unread,
Jul 15, 2012, 8:56:28 PM7/15/12
to rav...@googlegroups.com
Great idea Ryan!

Oren Eini (Ayende Rahien)

unread,
Jul 22, 2012, 8:44:46 PM7/22/12
to rav...@googlegroups.com
Add a reference to Raven.Abastractions

On Mon, Jul 23, 2012 at 1:41 AM, Eugene Niemand <eugene....@gmail.com> wrote:
How do I get the  Raven.Imports.Newtonsoft.Json  namespace? I'm using the Raven Lightweight assembly, do I need another references? When I just use Newtonsoft.Json and use the JsonIgnore decoration it still serializes and persist the property. I'm using 1.2 Unstable. 

Reply all
Reply to author
Forward
0 new messages