qt4cg / qtspecs

QT4 specifications
https://qt4cg.org/
Other
28 stars 15 forks source link

Serialization fallback. #641

Open michaelhkay opened 1 year ago

michaelhkay commented 1 year ago

I propose that we drop some serialization errors in favour of producing a fallback representation of the supplied value.

The rationale is that (a) serialization is often used in contexts like xsl:message where the primary purpose is diagnostic, and the last thing you want when producing diagnostics is a secondary error; and (b) seeing a fallback representation of an inappropriate value often shows you much more clearly what you have done wrong than any error message can do.

Compare with the .toString() method in Java and similar languages, which always outputs something even if it's not quite what you wanted.

I'm not proposing to change the principle that the output should always be syntactically valid (e.g. well formed XML or JSON).

I think some of the specific error conditions we might drop are:

Closely related, and perhaps best considered together: should the fn:string() function accept anything as input, and never raise an error?

ChristianGruen commented 1 year ago

Maybe we can also drop SERE0020

It is an error if a numeric value being serialized using the JSON output method cannot be represented in the JSON grammar (e.g. +INF, -INF, NaN).

…and output the values as strings (I wonder if it should be INF or Infinity?)

line-o commented 1 year ago

About serialising +INF, -INF and NaN: As we are not the first ones to discuss this there are several options

michaelhkay commented 10 months ago

This issue overlaps with issue #576

ndw commented 3 months ago

Consensus in Prague was that an extra serialization option to turn on the look-ahead behavior might be worth doing.

ndw commented 3 months ago

Also in Prague, we should go the standards route and represent NaN and the flavors of infinity with null.

ChristianGruen commented 3 months ago

Consensus in Prague was that an extra serialization option to turn on the look-ahead behavior might be worth doing.

What kind of look-ahead would be performed with that option?

ChristianGruen commented 3 months ago

An addendum: Thanks for the joint discussion in yesterday’s meeting. I haven’t understood all details due to audio issues, but I’d like to add that there are many existing cases in which the serialization of item sequences with the default xml method creates output that cannot be properly parsed back to the original representation. Examples:

(: multiple text nodes; results in `AC` :)
serialize(<a>A<b/>C</a>//text())

(: arbitrary items; results in `1 2 3` :)
serialize(1 to 3)

The same currently applies to all other serialization methods (html, text, etc.) except for json. I cannot see a good reason why we should pursue a different path for serializing JSON.

For the sake of completeness, this is what a newline item separator returns when two maps are serialized:

serialize(
  ({ "A": 1 }, { "B": 2 }),
  { 'item-separator': '&#xa;', 'method': 'adaptive' }
)

(: result :)
{"A":1}
{"B":2}