Possible bug: "Non-string or null key in data to be deserialized"

Hi,

I receive error “Non-string or null key in data to be deserialized” when I try to store document data which contains JSONObject.NULL value.

Error happens in com.couchbase.lite.Fleece.toCBLObject. It handles null correctly but not JSONObject .NULL

If you’d like help with this issue, we’ll need a little more information. Which product are you using (looks like either Java or Android). What version? Can we see the entire stack trace? Maybe some code?

Currently CBL Java/Android doesn’t support storing JSONObject and JSONObject.NULL. Can you also provide your use cases for the need to support JSONObject?

We use java and android 2.8 version.

Here is tests to reproduce it

import com.couchbase.lite.CouchbaseLite;
import com.couchbase.lite.Database;
import com.couchbase.lite.MutableDocument;
import com.couchbase.lite.internal.utils.JsonUtils;
import org.json.JSONObject;

import java.util.Collections;
import java.util.Map;

public class Test {

static {
    CouchbaseLite.init();
}

@org.junit.Test
public void testJSONObjectNullFail() throws Exception {
    Map<String, Object> testData = JsonUtils.fromJson(new JSONObject("{\"testValue\":null}"));

    assert testData.get("testValue") == JSONObject.NULL;

    Database db = new Database("test");

    MutableDocument docWithNull = new MutableDocument(testData);
    db.save(docWithNull);

    assert db.getDocument(docWithNull.getId()) != null;

    db.delete();
}

@org.junit.Test
public void testNullSuccess() throws Exception {
    Map<String, Object> testData = Collections.singletonMap("testValue", null);

    assert testData.get("testValue") != JSONObject.NULL;

    Database db = new Database("test");

    MutableDocument docWithNull = new MutableDocument(testData);
    db.save(docWithNull);

    assert db.getDocument(docWithNull.getId()) != null;

    db.delete();
}

}

There is no problem for us. I changed our code to use Jackson instead of org.json and everything is fine.
I only wanted to aware you about it.

Thanks very much! Glad to hear that everything is fine.

1 Like