Skip to content

Commit f18d5c8

Browse files
author
Burak Serdar
committed
Fix #654: inclusion of array should output an empty array if the array is empty in the doc
1 parent 3d62ee6 commit f18d5c8

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

crud/src/main/java/com/redhat/lightblue/eval/Projector.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,8 @@ private JsonNode project(JsonNodeFactory factory,
205205
project(factory, contextPath, cursor, ctx, true);
206206
cursor.parent();
207207
LOGGER.debug("Child object:{}", newNode);
208+
} else {
209+
newNode=factory.arrayNode();
208210
}
209211
} else {
210212
newNode = fieldNode;

crud/src/test/java/com/redhat/lightblue/eval/ProjectorTest.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -411,6 +411,18 @@ public void dont_project_unwanted_emptyArray() throws Exception {
411411
Assert.assertNull(pdoc.get(new Path("field6.nf5")));
412412
}
413413

414+
@Test
415+
public void project_wanted_emptyArray() throws Exception {
416+
// Set nf5 to an empty array
417+
jsonDoc.modify(new Path("field6.nf5"), JSON_NODE_FACTORY.arrayNode(), true);
418+
Projection p = EvalTestContext.projectionFromJson("{'field':'field6.*'}");
419+
Projector projector = Projector.getInstance(p, md);
420+
JsonDoc pdoc = projector.project(jsonDoc, JSON_NODE_FACTORY);
421+
System.out.println(pdoc);
422+
Assert.assertNotNull(pdoc.get(new Path("field6")));
423+
Assert.assertNotNull(pdoc.get(new Path("field6.nf5")));
424+
}
425+
414426
@Test
415427
public void include_then_exclude_626() throws Exception {
416428
Projection p = EvalTestContext.projectionFromJson("[ {'field':'field7','include':true,'match':{'field':'elemf3','op':'>','rvalue':3}},"

0 commit comments

Comments
 (0)