[RavenDB] Serialization without public setters and parameterless constructor

158 views
Skip to first unread message

Andrew Davey

unread,
May 19, 2010, 9:43:44 AM5/19/10
to ravendb
What is the extension point to enable serialization of classes that
look like this?

public class CustomerMoved : IDomainEvent {
public CustomerMoved(Guid customerId, string newAddress) {
CustomerId = customerId;
NewAddress = newAddress;
}

public readonly CustomerId;
public readonly NewAddress;
}

Not all the classes I want to save will be like this, only those that
implement IDomainEvent. So ideally I'd like a way to specify a
convention to use a certain formatter for classes that implement that
interface.

Where should I be looking to do something like this?

Matt

unread,
May 19, 2010, 10:18:45 AM5/19/10
to ravendb
You can define your own JsonContractResolver - (or use
DefaultContractResolver as a starting point)

You can define this in DocumentStore (when you create) you pass an
instance of DocumentConvetion with your own JsonContractResolver which
perhaps does special resolving where needed and falls back to
DefaultContractResolver?

Andrew Davey

unread,
May 19, 2010, 10:58:26 AM5/19/10
to ravendb
I played around with the Newtonsoft Json library. The JsonSerializer
seems to just work as-is without any customization. So I assume Raven
will just run with that. Nice.
Reply all
Reply to author
Forward
0 new messages