Converts a Java external object to a map, giving access to the instance methods of the object as dynamic functions.

object-map($object as jt:java.lang.Object) ➔ map(xs:string, function(*))





The supplied external object


map(xs:string, function(*))


Saxon availability

Requires Saxon-PE or Saxon-EE. Implemented since Saxon 9.9. Available for Java and C/C++ only (not .NET).

Notes on the Saxon implementation

Available since Saxon 9.9. Not available in SaxonCS.


The map returned by the function is as follows:

  • There is one entry named "this" whose value is a zero-arity function that returns $object.
  • For each non-static public method defined on the object's class, provided the name of the method is unique, there will be an entry whose key is the method name, and whose value is a (dynamic) function corresponding to the method. The arguments expected by the function correspond to the arguments declared for the method, and the result returned by the function similarly corresponds to the result of the method.
  • For each non-static public method defined on the object's class, provided the combination of the method's name and arity is unique, there will be an entry whose key has the form MMM_N where MMM is the method name, and N is the arity: for example if the object were an instance of java.lang.String, there would be an entry with key split_1 and another with key split_2 corresponding to the two versions of the String.split() method. There would be no entry for replace_2 because there are two arity-2 methods named replace.

The type conversions for the arguments and return values of the dynamic functions work in the same way as for other reflexive extension functions: see Converting arguments. The void=this convention is used: that is, a Java method whose declared return type is void is translated to a function that returns the target object as its result, to make it easier to write code that uses function chaining.

This function is called implicitly when an external object appears as the left-hand operand of the lookup operator "?". This means that, for example, Q{java:java.util.Locale}new("en")?getDisplayLanguage_0() returns the string "English".

For more complex use cases, the function can be called explicitly. For example, this query:

declare namespace StreamSource = ""; declare namespace map = ""; StreamSource:new() => saxon:object-map() => map:keys() => sort()


"equals", "equals_1", "getClass", "getClass_0", "getInputStream", "getInputStream_0", "getPublicId", "getPublicId_0", "getReader", "getReader_0", "getSystemId", "getSystemId_0", "hashCode", "hashCode_0", "notify", "notifyAll", "notifyAll_0", "notify_0", "setInputStream", "setInputStream_1", "setPublicId", "setPublicId_1", "setReader", "setReader_1", "this", "toString", "toString_0", "wait_0", "wait_1", "wait_2"