I'm using ravendb to serialize an object and test it through mstest.
I am getting this result: System.ArgumentException: Object serialized to String. RavenJObject instance expected.
Here is my code
public class Store
{
private static IDocumentStore store = createStore();
private static EmbeddableDocumentStore createStore()
{
var returnStore = new EmbeddableDocumentStore();
returnStore.DataDirectory = @"./PersistedData";
returnStore.Initialize();
return returnStore;
}
public static void Write(string value)
{
using (var session = store.OpenSession())
{
session.Store(value);
session.SaveChanges();
}
}
}
It seems the root cause is in how RavenJObject works as this throws the same error:
RavenJObject storeMe = RavenJObject.FromObject("errors", new JsonSerializer());
How do I do custom serialization in RavenDB?
To do custom serialization with a class you didn't write (so you can't attribute) implement Newtonsoft.Json.JsonConverter
Then register it like this:
using (var session = store.OpenSession())
{
session.Advanced.Conventions.CustomizeJsonSerializer = serializer => serializer.Converters.Add(MailAddressJsonConverter.Instance);
session.Store(mailAddress);
session.SaveChanges();
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With