Skip to content

Commit c570290

Browse files
committed
[enhancement] JSONSerializer recognizes new option exist:insert-final-newline
1 parent 616392e commit c570290

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

exist-core/src/main/java/org/exist/util/serializer/json/JSONSerializer.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,9 @@ public void serialize(Sequence sequence, Writer writer) throws SAXException {
7070
generator.disable(JsonGenerator.Feature.STRICT_DUPLICATE_DETECTION);
7171
}
7272
serializeSequence(sequence, generator);
73+
if ("yes".equals(outputProperties.getProperty(EXistOutputKeys.INSERT_FINAL_NEWLINE, "no"))) {
74+
generator.writeRaw('\n');
75+
}
7376
generator.close();
7477
} catch (IOException | XPathException e) {
7578
throw new SAXException(e.getMessage(), e);

exist-core/src/test/xquery/xquery3/serialize.xql

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -868,3 +868,29 @@ function ser:exist-insert-final-newline-true() {
868868
map {xs:QName("exist:insert-final-newline"): true()})
869869
return fn:ends-with($serialized, "
")
870870
};
871+
872+
declare
873+
%test:assertTrue
874+
function ser:exist-insert-final-newline-false-json() {
875+
let $doc := map { "a": 1 }
876+
let $serialized := fn:serialize($doc,
877+
map {
878+
"method": "json",
879+
"exist:insert-final-newline": false()
880+
}
881+
)
882+
return fn:ends-with($serialized, "}")
883+
};
884+
885+
declare
886+
%test:assertTrue
887+
function ser:exist-insert-final-newline-true-json() {
888+
let $doc := map { "a": 1 }
889+
let $serialized := fn:serialize($doc,
890+
map {
891+
"method": "json",
892+
"exist:insert-final-newline": true()
893+
}
894+
)
895+
return fn:ends-with($serialized, "
")
896+
};

0 commit comments

Comments
 (0)