Skip to content
This repository was archived by the owner on Nov 8, 2024. It is now read-only.

Commit bfee55f

Browse files
patricksmmskylef
authored andcommitted
feat(json): support dataStructure element in serialize
Allow passing the dataStructure element directly, instead of its content
1 parent 1282fee commit bfee55f

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

packages/json-serializer/lib/serializeJSON.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,13 @@ function collectElementByIDs(element) {
2020
}
2121

2222
function serializeJSON(element) {
23+
if (element.element === 'dataStructure') {
24+
return serializeJSON(element.content);
25+
}
26+
2327
const dataStructures = collectElementByIDs(element);
2428
const value = element.valueOf(undefined, dataStructures);
29+
2530
return JSON.stringify(value);
2631
}
2732

packages/json-serializer/test/serializeJSON-test.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,12 @@ describe('#serializeJSON', () => {
3333

3434
expect(serializeJSON(element)).to.equal('"hello world"');
3535
});
36+
37+
it('can serialize a dataStructure element', () => {
38+
const element = new namespace.elements.DataStructure(
39+
new namespace.elements.String('hello world')
40+
);
41+
42+
expect(serializeJSON(element)).to.equal('"hello world"');
43+
});
3644
});

0 commit comments

Comments
 (0)