olingo-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rare...@apache.org
Subject olingo-odata4 git commit: OLINGO-981: validating to make sure the navigation property is set to allow nullable before allowing the null as the binding value
Date Wed, 27 Jul 2016 16:47:52 GMT
Repository: olingo-odata4
Updated Branches:
  refs/heads/master 37fe8e19b -> d9ae1f68e


OLINGO-981: validating to make sure the navigation property is set to allow nullable before
allowing the null as the binding value


Project: http://git-wip-us.apache.org/repos/asf/olingo-odata4/repo
Commit: http://git-wip-us.apache.org/repos/asf/olingo-odata4/commit/d9ae1f68
Tree: http://git-wip-us.apache.org/repos/asf/olingo-odata4/tree/d9ae1f68
Diff: http://git-wip-us.apache.org/repos/asf/olingo-odata4/diff/d9ae1f68

Branch: refs/heads/master
Commit: d9ae1f68efa6da7c272d230a70a60c3a7b3cf9a0
Parents: 37fe8e1
Author: Ramesh Reddy <rareddy@jboss.org>
Authored: Wed Jul 27 11:47:03 2016 -0500
Committer: Ramesh Reddy <rareddy@jboss.org>
Committed: Wed Jul 27 11:47:03 2016 -0500

----------------------------------------------------------------------
 .../json/ODataJsonDeserializer.java             |  5 +++--
 .../json/ODataJsonDeserializerEntityTest.java   | 20 +++++++++++++++-----
 2 files changed, 18 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/d9ae1f68/lib/server-core/src/main/java/org/apache/olingo/server/core/deserializer/json/ODataJsonDeserializer.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/deserializer/json/ODataJsonDeserializer.java
b/lib/server-core/src/main/java/org/apache/olingo/server/core/deserializer/json/ODataJsonDeserializer.java
index 5f98bd7..d30d973 100644
--- a/lib/server-core/src/main/java/org/apache/olingo/server/core/deserializer/json/ODataJsonDeserializer.java
+++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/deserializer/json/ODataJsonDeserializer.java
@@ -443,10 +443,11 @@ public class ODataJsonDeserializer implements ODataDeserializer {
         throw new DeserializerException("Binding annotation: " + key + " must be a string
value.",
             DeserializerException.MessageKeys.INVALID_ANNOTATION_TYPE, key);
       }
-      if (jsonNode.isNull()) {
+      if (edmNavigationProperty.isNullable() && jsonNode.isNull()) {
         bindingLink.setBindingLink(null);
       } else {
-        bindingLink.setBindingLink(jsonNode.asText());
+        assertIsNullNode(key, jsonNode);
+        bindingLink.setBindingLink(jsonNode.asText());        
       }
       bindingLink.setType(Constants.ENTITY_BINDING_LINK_TYPE);
     }

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/d9ae1f68/lib/server-test/src/test/java/org/apache/olingo/server/core/deserializer/json/ODataJsonDeserializerEntityTest.java
----------------------------------------------------------------------
diff --git a/lib/server-test/src/test/java/org/apache/olingo/server/core/deserializer/json/ODataJsonDeserializerEntityTest.java
b/lib/server-test/src/test/java/org/apache/olingo/server/core/deserializer/json/ODataJsonDeserializerEntityTest.java
index 368dda6..c92edfc 100644
--- a/lib/server-test/src/test/java/org/apache/olingo/server/core/deserializer/json/ODataJsonDeserializerEntityTest.java
+++ b/lib/server-test/src/test/java/org/apache/olingo/server/core/deserializer/json/ODataJsonDeserializerEntityTest.java
@@ -1023,19 +1023,29 @@ public class ODataJsonDeserializerEntityTest extends AbstractODataDeserializerTe
   }
 
   @Test
-  public void bindingOperationNullOnToOne() throws Exception {
+  public void bindingOperationNullOnToOneNonNull() throws Exception {
     String entityString =
         "{\"PropertyInt16\":32767,"
             + "\"PropertyString\":\"First Resource - positive values\","
             + "\"NavPropertyETTwoPrimOne@odata.bind\":null"
             + "}";
-    
-    final Entity entity = deserialize(entityString, "ETAllPrim");
-    assertEquals("First Resource - positive values", entity.getProperty("PropertyString").asPrimitive());
-    assertNull(entity.getNavigationBinding("NavPropertyETTwoPrimOne").getBindingLink());
+    expectException(entityString, "ETAllPrim",
+        DeserializerException.MessageKeys.INVALID_NULL_ANNOTATION);    
   }
   
   @Test
+  public void bindingOperationNullOnToOneNull() throws Exception {
+    String entityString =
+        "{\"PropertyInt16\":32767,"
+            + "\"PropertyString\":\"First Resource - positive values\","
+            + "\"NavPropertyETAllPrimOne@odata.bind\":null"
+            + "}";
+    
+    final Entity entity = deserialize(entityString, "ETTwoPrim");
+    assertEquals("First Resource - positive values", entity.getProperty("PropertyString").asPrimitive());
+    assertNull(entity.getNavigationBinding("NavPropertyETAllPrimOne").getBindingLink());
+  }  
+  @Test
   public void bindingOperationNullOnToMany() throws Exception {
     String entityString =
         "{\"PropertyInt16\":32767,"


Mime
View raw message