Skip to content

Commit 6fb3fae

Browse files
ryanjdewaebadirad
authored andcommitted
GH #1652 If $type is undefined, don't nest (#1729)
* GH #1652 If $type is undefined, don't nest * Make flow-lib XQuery consistent with SJS change
1 parent 9cbe41f commit 6fb3fae

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

marklogic-data-hub/src/main/resources/ml-modules/root/data-hub/4/impl/flow-lib.sjs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,7 @@ function instanceToCanonicalJson(entityInstance) {
386386
if (key === '$attachments' || key === '$type' || key === '$version') {
387387
} else {
388388
let instanceProperty = entityInstance[key];
389-
if (instanceProperty instanceof Array) {
389+
if (instanceProperty instanceof Array) {
390390
let a = [];
391391
let i = 0;
392392
for (i = 0; i < instanceProperty.length; i++) {
@@ -405,7 +405,11 @@ function instanceToCanonicalJson(entityInstance) {
405405
}
406406
}
407407
let rootObject = {};
408-
rootObject[entityInstance['$type']] = o;
408+
if (entityInstance['$type'] != undefined) {
409+
rootObject[entityInstance['$type']] = o;
410+
} else {
411+
rootObject = o;
412+
}
409413
return rootObject;
410414
}
411415

marklogic-data-hub/src/main/resources/ml-modules/root/data-hub/4/impl/flow-lib.xqy

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -529,7 +529,6 @@ declare function flow:make-legacy-envelope($content, $headers, $triples, $data-f
529529
declare function flow:instance-to-canonical-json(
530530
$entity-instance as map:map) as json:object
531531
{
532-
let $root-object := json:object()
533532
let $o :=
534533
if ( map:contains($entity-instance, "$ref") ) then
535534
map:get($entity-instance, "$ref")
@@ -569,7 +568,13 @@ declare function flow:instance-to-canonical-json(
569568
)
570569
return
571570
$o
572-
let $_ := map:put($root-object, map:get($entity-instance, "$type"), $o)
571+
let $root-object :=
572+
if (map:contains($entity-instance, "$type")) then
573+
let $object := json:object()
574+
let $_ := map:put($object, map:get($entity-instance, "$type"), $o)
575+
return $object
576+
else
577+
$o
573578
return
574579
$root-object
575580
};

0 commit comments

Comments
 (0)