It would be useful to have Java Collection to sequence, Java Collection to array(*) and Java Map to map(*) converters. Either the conversion module or a Java helper module would be useful. Saxon does the Collection to sequence automatically in its Java bindings - https://www.saxonica.com/documentation10/index.html#!extensibility/functions....
Thanks for the link. I didn’t know that Saxon does different things if they are returned by either a constructor or a method. This looks like a pragmatic solution, but I’m not completely convinced if that’s a good idea. In my point of view, we shouldn’t make a difference if a data structure is returned by a constructor or a (possibly static generator) function.
My rational for not converting them to arrays is to avoid a performance overhead when dealing with a large number of items, but I can see how null values could be complicated to manage if the BaseX sequence interface doesn't do flattening itself (otherwise, you could map null to the empty sequence instance like with the general Java mapping).
I agree, I would also prefer sequences to arrays whenever possible, as they are supported much better in XQuery.
From a performance point of view, arrays and sequences are internally
based on the same data structure, so it shouldn’t make a difference if you create arrays or sequences. I was mostly thinking about cases in which null values are deliberately added to a list. If such a list is converted to a sequence, the positions of the resulting sequence entries wouldn’t reflect the original positions anymore.
Having said that, I checked the existing code and I noticed two things:
1. If Java arrays are returned, null entries are already ignored by our mapper (so it would just be consistent to do the same for other data structures). 2. If a String array contains null values, an unexpected runtime error is currently raised because we didn’t think of this case [1]…
Saxon does better, it returns an XQuery error – and I think we should do the same:
SXJE0051 Returned array contains null values: cannot convert to items
Out of interest, and as you seem to have worked with both the Saxon and BaseX Java mapping: Did you encounter other mapping details that you believe are handled better in one of the processors?
When the Java mapping was introduced, there were no maps and arrays visible on the horizon. I’ll definitely have more on that now.
Cheers, Christian
[1] https://github.com/BaseXdb/basex/blob/master/basex-core/src/main/java/org/ba...