Hi all, hi Reece,
I have remastered the conversion of Java values: Objects of unknown type are now returned as function item, and the conversion of the contained value can be enforced by invoking the function item:
declare namespace Scanner = 'java:java.util.Scanner'; let $scanner := Scanner:new("A B C") => Scanner:useDelimiter(" ") return $scanner()
If no conversion rule is defined for a Java object type, the string representation (i.e., the one that’s returned by Object.toString) is returned. The convert:from-java() function is obsolete now, so it was kicked out again.
Furthermore, the middle dot extension was enhanced to support array arguments (such as byte[]): As square brackets are illegal QName characters, array types can now be addressed with three dots:
Q{java.lang.String}new·byte...(xs:hexBinary('414243'))
More details can be found in the updated documentation [1]. Everyone’s feedback is welcome.
Best, Christian
[1] https://docs.basex.org/wiki/Java_Bindings
On Fri, Jul 2, 2021 at 3:44 PM Christian Grün christian.gruen@gmail.com wrote:
I have finalized the convert:from-java function [1], and I have added new conversion rules for XQuery arrays [2]. As it was about time, I have also revised our documentation on Java Bindings [3].
Cheers Christian
[1] https://docs.basex.org/wiki/Conversion_Module#convert:from-java [2] https://github.com/BaseXdb/basex/issues/2020 [3] https://docs.basex.org/wiki/Java_Bindings#Data_Types
On Wed, Jun 30, 2021 at 11:29 AM Christian Grün christian.gruen@gmail.com wrote:
Thanks for testing.
Trying to use convert:from-java on a list of a custom Java object, I get: [convert:java] Java object cannot be converted: "Word(text=test, normalized=test)".
It should just marshal the Java object like is done with the Java interop in this case.
As the function triggers an explicit conversion, I’d like to inform the caller that no conversion is possible (at least for now; we may find other Java types that could be converted). I’ll certainly need to add that in the documentation.
I’m still not sure if I will keep the recursive conversion (maybe that should be controlled via an additional argument). For maps, it’s certainly helpful.