Patch losing "$type" json meta data

72 views
Skip to first unread message

Lucas bode

unread,
Feb 20, 2018, 10:51:58 AM2/20/18
to RavenDB - 2nd generation document database
We are trying to store the class type meta data in our json using the following code example...


var settings = new Newtonsoft.Json.JsonSerializerSettings
{
    TypeNameHandling = Newtonsoft.Json.TypeNameHandling.Auto
};

This stores a "$type" property when saving the json to RavenDB. It works perfectly fine for all of the GET, POST, and PUT operations. However if you attempt to Patch an object in a document, the "$type" property is lost. Is this a bug?

Oren Eini (Ayende Rahien)

unread,
Feb 21, 2018, 2:55:37 AM2/21/18
to ravendb
I'm not sure, how are you performing the patch?

Hibernating Rhinos Ltd  

Oren Eini l CEO Mobile: + 972-52-548-6969

Office: +972-4-622-7811 l Fax: +972-153-4-622-7811

 


--
You received this message because you are subscribed to the Google Groups "RavenDB - 2nd generation document database" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ravendb+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Lucas bode

unread,
Feb 21, 2018, 11:12:59 AM2/21/18
to RavenDB - 2nd generation document database
Sorry if I didn't explain very well. I'm basically trying to store a list of objects that may be base classes or classes inheriting from the base class. When I pull those items out of the json I would like them to deserialize as the correct class. I attached a file with two tests, one that succeeds and one that fails that I would expect to succeed. I also attached two images that show that the $type property included in the json is being lost after the patch for some reason. 

Any help would be greatly appreciated. Thanks!

To unsubscribe from this group and stop receiving emails from it, send an email to ravendb+u...@googlegroups.com.
2018-02-21 10_09_03-Edit Document _ Raven.Studio.png
2018-02-21 10_08_45-Edit Document _ Raven.Studio.png
RavenPatch_TypeAttributeSerialization.cs

Grisha Kotler

unread,
Mar 4, 2018, 11:34:02 AM3/4/18
to rav...@googlegroups.com
Do you need to replace the Classes object?

This patch works:
session.Advanced.Patch<ClassList, string>(classList.Id, x => x.Classes[0].Property1, "ABCDEFG");

Hibernating Rhinos Ltd  cid:image001.png@01CF95E2.8ED1B7D0

Grisha Kotler l RavenDB Core Team Developer Mobile: +972-54-586-8647

RavenDB paving the way to "Data Made Simplehttp://ravendb.net/


To unsubscribe from this group and stop receiving emails from it, send an email to ravendb+unsubscribe@googlegroups.com.

Grisha Kotler

unread,
Mar 4, 2018, 12:12:53 PM3/4/18
to rav...@googlegroups.com
You need to customize the JsonSerializer before DocumentStore.Initialize().

store.Conventions.CustomizeJsonSerializer = serializer => serializer.TypeNameHandling = TypeNameHandling.All;

Hibernating Rhinos Ltd  cid:image001.png@01CF95E2.8ED1B7D0

Grisha Kotler l RavenDB Core Team Developer Mobile: +972-54-586-8647

Office: +972-4-622-7811 l Fax: +972-153-4-622-7811

RavenDB paving the way to "Data Made Simplehttp://ravendb.net/


Reply all
Reply to author
Forward
0 new messages