Project

Profile

Help

Conversion from text() to an Object

Added by K L over 6 years ago

Hi

After updating to saxon 9.7, we have encountered an issue related to [text() cannot be converted to a java Object] When using a previous version saxon 9.4 there are no conversion issues.

This is a snippet of the XQuery with the conversion:

  1. declare namespace java_lang_String = "java:java.lang.String"; let $castVar := ( java_lang_String:toUpperCase($out_pri_Response/key[1]/text()) . We get an error: Cannot convert value class net.sf.saxon.tree.tiny.TinyTextImpl of type text() to class java.lang.String.

  2. The same goes when using java_lang_Integer:shortValue($out_pri_Response/key[1]/text()). We get an error : Cannot convert value.. of type text() to java.lang.Integer.

However, when using a static java function that has a primitive type parameter, the conversion works: let $castVar := (java_lang_Integer:toHexString($out_pri_Response/key[1]/text()) (text() is converted to int)

(The xquery is generic regardless of what java function is called so we would like to avoid a ( cast as *) declaration.)

Is there a setting need to be updated in our Configuration to enable a compatible conversion? Thanks.


Replies (2)

RE: Conversion from text() to an Object - Added by Michael Kay over 6 years ago

This seems to be related to bug 2328 (https://saxonica.plan.io/issues/2328), where comment #4 suggests that we patched the code in 9.6 to make String.split() work in the way that you clearly expect.

Note that your third example (toHexString) is completely different, because in that case you're calling a static method.

If I run the query

Q{java:java.lang.String}toUpperCase( 'x,y,z' )

then it works: so we've clearly done part of what bug 2328 suggests.

But there seems to be no attempt in the conversion rules for extension functions to apply atomization. Except, intriguingly, in code in PJConverter that is commented out. (It was also commented out in 9.6 and 9.7, and didn't exist in 9.5). I can't see any convincing reason why we shouldn't atomize here - except that changes in this area have a nasty habit of causing some existing applications to break.

RE: Conversion from text() to an Object - Added by Michael Kay over 6 years ago

Transferred to

https://saxonica.plan.io/issues/3388

Please move the conversation there.

    (1-2/2)

    Please register to reply