Details
-
Improvement
-
Resolution: Won't Fix
-
Trivial
-
1.3.7
-
None
-
all
Description
Hi there,
There was some discussion about the 1.3x SDK not forcefully injecting the "ID" property with the object's key.
The previous discussion was briefly mentioned here:
https://www.couchbase.com/issues/browse/NCBC-564
For convenience:
------------------------------
I am having problems with this section of code:
if (!IsArrayOrCollection(typeof(T)))
{ value = DocHelper.InsertId(value, key); }I am managing all the document IDs myself in my application. But DocHelper keeps interfering with my ID during deserialization. Is there a way we can possibly set a flag that wont interfere with my JSON ?
One example: All my domain objects have a strongly typed Guid as their ID.
The KEY to an Account object is "acct:aaaa-bb-cc-dd".
POCO in C#:
public class Account{
public Guid Id
}
I format the key to this object inside my App; however, during deserialization DocHelper interferes with the JSON by injecting the KEY: "acct:aaaa-bb-cc-dd" into the ID property in the JSON before deseralization.
So when Newtonsoft deserializes the JSON with the injected DocHelper Id:Key:"acct:aaaa-bb-cc-dd" cannot be converted to a Guid because of the prefix "acct:" is an invalid Guid format. I'd prefer the SDK not interfere with any of my ser/deser JSON.
Perhaps we can add some flag that can short circuit the DocHelper injection?
------------------------------
Any suggestions on implementation?
As a static configuration variable on DocHelper or via App.config?
Of course, the default behavior would be to keep things as is for a non-breaking change.
Using something like a static property:
public static class DocHelper
{
public static bool DisableIdInsert{get;set;}
public static string InsertId(string json, string id)
{
if (!DisableIdInsert && !json.Contains("\"id\""))
return json;
}
}
Thanks,
Brian