In RavenDB 2.0
using Raven.Imports.Newtonsoft.Json public class Foo { [JsonIgnore] public string Bar { get; set; } }
Since it uses a built-in copy of raven for json.net - WebApi will not receive the attribute.
In RavenDB 1.0 or 2.0
You can customize json serialization of your object directly using a custom json contract recognizer.
public class CustomContractResolver : DefaultRavenContractResolver { public CustomContractResolver(bool shareCache) : base(shareCache) { } protected override List<MemberInfo> GetSerializableMembers(Type objectType) { var members = base.GetSerializableMembers(objectType); if (objectType == typeof(Foo)) members.RemoveAll(x => x.Name == "Baz"); return members; } }
Connect it to the document repository during initialization:
documentStore.Conventions.JsonContractResolver = new CustomContractResolver(true); documentStore.Initialize();
Since it is not connected anywhere, it will only affect RavenDB. Customize it as you like, according to your needs.
Matt johnson
source share