.NET GetJSON operation throws System.ArgumentNullException

NCBC-306: .NET GetJSON operation throws null reference exception
Add support for null values persisted for a key via the
CouchbaseClientExtensions.GetJson(…) method. This method will no
longer thrown a NullReferenceException when the value store for a
key is null and instead simply return null.


  •    public void Test_That_GetJson_Supports_Null_Values()
  •    {
  •        var key = "A_NULL_THING";
  •        var result = Client.StoreJson(StoreMode.Set, key, null);
  •        Assert.AreEqual(true, result);
  •        var nullResult = Client.GetJson<Thing>(key);
  •        Assert.AreEqual(null, nullResult);
  •    }

I’m not sure this test works for all cases. Say I just started my application can called

var returnedString = Client.GetJson(key);

But there isn’t anything in the system because I just started up, I’ll get a ‘System.ArgumentNullException’ because:
public static T GetJson(this ICouchbaseClient client, string key) where T : class
var json = client.Get(key);
return json == Null ? null : DeserializeObject(key, json);
The value ‘json’ will actually equal null. Since in this test it won’t equal the string “Null”, it will attempt to call DeserializeObject(key, json), with a null value for ‘json’.

see following test
public void Test_That_GetJson_Supports_Empty_Values()
//ensure key and value are not stored in the system
var nullResult = Client.GetJson(“my key”);
Assert.AreEqual(null, nullResult);

benhysell -

Ah, your right! That test only verifies that null value that has been persisted, won’t throw and ArgumentNullException. In this case, the response should be a KEY_NOT_FOUND exception, since, well…the key doesn’t exist in the database.

If you would like to file a bug (so you can track the progress/resolution), you can do so here: http://www.couchbase.com/issues/browse/NCBC