[OLINGO-590] Fix: Single value navigation properties with null values will be correctly deserialized

This commit is contained in:
Christian Holzer 2015-03-11 17:19:42 +01:00
parent 8b4947b868
commit f6fa1eeca7
2 changed files with 21 additions and 2 deletions

View File

@ -250,7 +250,8 @@ public class ODataJsonDeserializer implements ODataDeserializer {
EntitySetImpl inlineEntitySet = new EntitySetImpl(); EntitySetImpl inlineEntitySet = new EntitySetImpl();
inlineEntitySet.getEntities().addAll(consumeEntitySetArray(edmNavigationProperty.getType(), jsonNode)); inlineEntitySet.getEntities().addAll(consumeEntitySetArray(edmNavigationProperty.getType(), jsonNode));
link.setInlineEntitySet(inlineEntitySet); link.setInlineEntitySet(inlineEntitySet);
} else if (!jsonNode.isArray() && !jsonNode.isValueNode() && !edmNavigationProperty.isCollection()) { } else if (!jsonNode.isArray() && (!jsonNode.isValueNode() || jsonNode.isNull())
&& !edmNavigationProperty.isCollection()) {
link.setType(ODataLinkType.ENTITY_NAVIGATION.toString()); link.setType(ODataLinkType.ENTITY_NAVIGATION.toString());
if (!jsonNode.isNull()) { if (!jsonNode.isNull()) {
Entity inlineEntity = consumeEntityNode(edmNavigationProperty.getType(), (ObjectNode) jsonNode); Entity inlineEntity = consumeEntityNode(edmNavigationProperty.getType(), (ObjectNode) jsonNode);

View File

@ -121,7 +121,25 @@ public class ODataDeserializerDeepInsertTest extends AbstractODataDeserializerTe
throw e; throw e;
} }
} }
@Test
public void expandedToOneValidNullValue() throws Exception {
String entityString =
"{\"PropertyInt16\":32767,"
+ "\"NavPropertyETAllPrimOne\":null"
+ "}";
InputStream stream = new ByteArrayInputStream(entityString.getBytes());
EdmEntityType edmEntityType = edm.getEntityType(new FullQualifiedName("Namespace1_Alias", "ETTwoPrim"));
final Entity entity = OData.newInstance().createDeserializer(ODataFormat.JSON).entity(stream, edmEntityType);
assertEquals(1, entity.getNavigationLinks().size());
final Link link = entity.getNavigationLinks().get(0);
assertEquals("NavPropertyETAllPrimOne", link.getTitle());
assertNull(link.getInlineEntity());
assertNull(link.getInlineEntitySet());
}
@Test(expected = DeserializerException.class) @Test(expected = DeserializerException.class)
public void expandedToOneInvalidStringValue() throws Exception { public void expandedToOneInvalidStringValue() throws Exception {
String entityString = String entityString =