diff --git a/source/java/org/alfresco/rest/api/impl/NodesImpl.java b/source/java/org/alfresco/rest/api/impl/NodesImpl.java index 3cf4f41f3a..8c839dfb90 100644 --- a/source/java/org/alfresco/rest/api/impl/NodesImpl.java +++ b/source/java/org/alfresco/rest/api/impl/NodesImpl.java @@ -1197,6 +1197,15 @@ public class NodesImpl implements Nodes { value = Node.lookupUserInfo((String)value, mapUserInfo, sr.getPersonService()); } + + // Empty (zero length) string values are considered to be + // null values, and will be represented the same as null + // values (i.e. by non-existence of the property). + if (value != null && value instanceof String && ((String) value).isEmpty()) + { + continue; + } + props.put(qName.toPrefixString(namespaceService), value); } } diff --git a/source/test-java/org/alfresco/rest/api/tests/NodeApiTest.java b/source/test-java/org/alfresco/rest/api/tests/NodeApiTest.java index 1959bd6aef..cb3b5e5200 100644 --- a/source/test-java/org/alfresco/rest/api/tests/NodeApiTest.java +++ b/source/test-java/org/alfresco/rest/api/tests/NodeApiTest.java @@ -3544,6 +3544,49 @@ public class NodeApiTest extends AbstractSingleNetworkSiteTest assertEquals("The quick brown fox jumps over the lazy dog", textContent); } + @Test + public void testGetNodeWithEmptyProperties() throws Exception + { + setRequestContext(user1); + + String myNodeId = getMyNodeId(); + + // create folder f1 + Folder folderResp = createFolder(myNodeId, "fld1_" + RUNID); + String f1Id = folderResp.getId(); + + String nodeName = "f1 link"; + String nodeType = "app:folderlink"; + String propertyName = "cm:destination"; + + Map props = new HashMap<>(); + props.put(propertyName, ""); + + Node nodeResp = createNode(f1Id, nodeName, nodeType, props); + String nodeId = nodeResp.getId(); + + Node n1 = new Node(); + n1.setName(nodeName); + n1.setNodeType(nodeType); + n1.setIsFolder(true); + // note: parent of the link (not where it is pointing) + n1.setParentId(f1Id); + n1.setAspectNames(Collections.singletonList("cm:auditable")); + // Empty (zero length) string values are considered to be + // null values, and will be represented the same as null + // values (i.e. by non-existence of the property). + n1.setProperties(null); + + // Check create response. + n1.expected(nodeResp); + + HttpResponse httpResponse = getSingle(NodesEntityResource.class, nodeId, null, 200); + nodeResp = RestApiUtil.parseRestApiEntry(httpResponse.getJsonResponse(), Node.class); + + // Check get response. + n1.expected(nodeResp); + } + /** * Tests optional lookup of Allowable Operations (eg. when getting node info, listing node children, ...) * diff --git a/source/test-java/org/alfresco/rest/api/tests/TestPeople.java b/source/test-java/org/alfresco/rest/api/tests/TestPeople.java index 73df582d29..bbf2efc397 100644 --- a/source/test-java/org/alfresco/rest/api/tests/TestPeople.java +++ b/source/test-java/org/alfresco/rest/api/tests/TestPeople.java @@ -77,6 +77,7 @@ public class TestPeople extends EnterpriseTestApi private static final QName PROP_TELEHASH = QName.createQName("test.people.api", "telehash"); private static final QName ASPECT_LUNCHABLE = QName.createQName("test.people.api", "lunchable"); private static final QName PROP_LUNCH = QName.createQName("test.people.api", "lunch"); + private static final QName PROP_LUNCH_COMMENTS = QName.createQName("test.people.api", "lunchcomments"); private People people; private Iterator accountsIt; private TestNetwork account1; @@ -577,6 +578,7 @@ public class TestPeople extends EnterpriseTestApi Map nodeProps = new HashMap<>(); // The papi:lunchable aspect should be auto-added for the papi:lunch property nodeProps.put(PROP_LUNCH, "Falafel wrap"); + nodeProps.put(PROP_LUNCH_COMMENTS, ""); // These properties should not be present when a person is retrieved // since they are present as top-level fields. @@ -629,6 +631,11 @@ public class TestPeople extends EnterpriseTestApi assertEquals("Doc", person.getFirstName()); assertEquals("Falafel wrap", person.getProperties().get("papi:lunch")); assertTrue(person.getAspectNames().contains("papi:lunchable")); + + // Empty (zero length) string values are considered to be + // null values, and will be represented the same as null + // values (i.e. by non-existence of the property). + assertNull(person.getProperties().get("papi:lunchcomments")); // Check that no properties are present that should have been filtered by namespace. for (String key : person.getProperties().keySet()) diff --git a/source/test-resources/models/people-api.xml b/source/test-resources/models/people-api.xml index a449e79108..199caa2998 100644 --- a/source/test-resources/models/people-api.xml +++ b/source/test-resources/models/people-api.xml @@ -49,6 +49,10 @@ d:text false + + d:text + false +