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

This commit is contained in:
Ramesh Reddy 2016-07-27 11:47:03 -05:00
parent 37fe8e19b0
commit d9ae1f68ef
2 changed files with 18 additions and 7 deletions

View File

@ -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);
}

View File

@ -1023,18 +1023,28 @@ 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 =