exist icon indicating copy to clipboard operation
exist copied to clipboard

[BUG] JSON serialization of sequences

Open line-o opened this issue 2 years ago • 4 comments

Describe the bug

This query

serialize((1 to 5), map{"method":"json"})

evaluates to [1,2,3,4,5].

The XQuery specification of the JSON serialization method says that an error should be raised instead: A sequence of length greater than one in the data model instance will result in a serialization error [err:SERE0023].

Expected behavior

JSON serialization to be spec compliant.

To Reproduce

xquery version "3.1";

module namespace t="http://exist-db.org/xquery/test";

declare namespace test="http://exist-db.org/xquery/xqsuite";

declare
    %test:assertError("SERE0023")
function t:test() {
    serialize((1 to 5), map{"method":"json"})
};

Context (please always complete the following information)

Build: eXist-6.2.0 (c8fa4958b6d4a50bd0cba7f3e76a150226414187) Java: 11.0.18 (Debian) OS: Linux 5.15.49-linuxkit-pr (aarch64)

Additional context

  • How is eXist-db installed? docker image
  • Any custom changes in e.g. conf.xml? none

line-o avatar Jul 21 '23 14:07 line-o

It seems that there is discussion in the XQuery 4 working group to allow sequences to be serialised to JSON arrays.

This only requires one change: serializing a sequence of length >1 should output the sequence as if it were an array, rather than raising an error.

from https://github.com/qt4cg/qtspecs/issues/576

We could keep our implementation as-is, knowing it will be part of the upcoming spec. Which means this is the current, shared understanding of the correct approach.

line-o avatar Jul 22 '23 08:07 line-o

As discussed in the Community Call, perhaps this issue should be resolved as a “won’t fix” - since, as Michael Kay proposes, XQuery 4 is going to behave as eXist already does.

joewiz avatar Jul 24 '23 18:07 joewiz

As discussed in the Community Call, perhaps this issue should be resolved as a “won’t fix”

@joewiz I feel that that is a bit of a dangerous proposition. At the moment:

  1. XQuery 4 has not been finalised or finished. There is no set timeline for that to happen.
  2. eXist-db does not intentionally support any draft aspects of XQuery 4.

As eXist-db is aiming for XQuery 3.1 compliance, I think we should fix this for eXist-db 7.0.0.

adamretter avatar Jul 25 '23 17:07 adamretter

This issue came up today in the working group meeting. In the related issue qt4cg/qtspecs#641 the discussion went further. Allowing sequences to be serialised to JSON has implications on the streamability of of the output as we have to look ahead, and buffer, the data before we can output the first character as it might be [ or not depending on the length of the sequence.

line-o avatar Jun 05 '24 15:06 line-o