Android: Enhancement for the IOT-764
authorTim Kourt <tim.a.kourt@intel.com>
Tue, 6 Oct 2015 21:08:27 +0000 (14:08 -0700)
committerPatrick Lankswert <patrick.lankswert@intel.com>
Wed, 7 Oct 2015 14:09:28 +0000 (14:09 +0000)
It is OK now to do the following:

OcRepresentation rep = new OcRepresentation();
OcRepresentation repNull = null;
rep.setValue("key", repNull);

Change-Id: I10d554490190561e40cc97c8a1973f6ace0478cd
Signed-off-by: Tim Kourt <tim.a.kourt@intel.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/3651
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Uze Choi <uzchoi@samsung.com>
Reviewed-by: Patrick Lankswert <patrick.lankswert@intel.com>
android/android_api/base/jni/JniOcRepresentation.cpp
android/android_api/base/src/androidTest/java/org/iotivity/base/OcRepresentationTest.java

index 5302a76..3c69be6 100644 (file)
@@ -170,10 +170,17 @@ JNIEXPORT void JNICALL Java_org_iotivity_base_OcRepresentation_setValueRepresent
     if (!rep) return;
 
     std::string key = env->GetStringUTFChars(jKey, nullptr);
-    OCRepresentation *value = JniOcRepresentation::getOCRepresentationPtr(env, jValue);
-    if (!value) return;
 
-    rep->setValue(key, *value);
+    if (jValue)
+    {
+        OCRepresentation *value = JniOcRepresentation::getOCRepresentationPtr(env, jValue);
+        if (!value) return;
+        rep->setValue(key, *value);
+    }
+    else
+    {
+        rep->setNULL(key);
+    }
 }
 
 /*
index cbed2d5..c7b5f30 100644 (file)
@@ -190,6 +190,12 @@ public class OcRepresentationTest extends InstrumentationTestCase {
     public void testAttributeAccessByType() throws OcException {
         OcRepresentation rep = new OcRepresentation();
 
+        //null
+        OcRepresentation repNull = null;
+        rep.setValue("nullKey", repNull);
+        OcRepresentation repNullActual = rep.getValue("nullKey");
+        assertNull(repNullActual);
+
         //integer
         String intK = "intK";
         int intV = 4;