Interface ValueCoercible
- All Superinterfaces:
Boxed<org.graalvm.polyglot.Value>, org.graalvm.polyglot.proxy.Proxy, org.graalvm.polyglot.proxy.ProxyObject
- All Known Subinterfaces:
PooledValueCoercible
Micronaut Python bridge classes implement this interface so Java code can keep a strongly typed
wrapper while GraalPy can still interact with the original Python object through
ProxyObject. The interface also defines Micronaut-specific proxy members used to recover
the generated host wrapper and to bridge generated JavaBean-style accessors back to Python
attributes.
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic interfaceBuild-time generated JavaBean accessor aliases for Python wrappers.static final recordPrivate host reference exposed throughHOST_OBJECT_MEMBER. -
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptiondefault org.graalvm.polyglot.Value$unbox()Unboxes this wrapper for Micronaut conversion infrastructure.@NonNull org.graalvm.polyglot.ValueReturns the wrapped Python value.default @Nullable ObjectExposes the wrapped Python value as a polyglot proxy member.default ObjectReturns member keys exposed by the wrapped Python object.default booleanTests whether a member is available through this proxy.static @Nullable ValueCoerciblehostObject(@Nullable org.graalvm.polyglot.Value value) Extracts a generated Java wrapper from a polyglot value when one is available.static @Nullable ObjecthostObject(@Nullable org.graalvm.polyglot.Value value, Class<?> targetType) Extracts a host object of the requested type from a polyglot value.static @Nullable ValueCoerciblehostObject(@Nullable org.graalvm.polyglot.proxy.ProxyObject value) Extracts a generated Java wrapper from a proxy object when one is available.static @Nullable ObjecthostObject(@Nullable org.graalvm.polyglot.proxy.ProxyObject value, Class<?> targetType) Extracts a host object of the requested type from a proxy object.static booleanmatchesArgument(org.graalvm.polyglot.Value value, Class<?> targetType) Match one Python argument against a Java parameter type without conversion.default voidWrites a member to the wrapped Python object.Methods inherited from interface org.graalvm.polyglot.proxy.ProxyObject
removeMember
-
Field Details
-
HOST_OBJECT_MEMBER
- See Also:
-
AS_POLYGLOT_VALUE_MEMBER
- See Also:
-
-
Method Details
-
asPolyglotValue
Returns the wrapped Python value.The returned value belongs to the runtime context that created this wrapper, except for pooled wrappers where
PooledValueCoercible.asPolyglotValue(org.graalvm.polyglot.Context)can resolve an equivalent value for a specific event-loop context.- Returns:
- The wrapped Python polyglot value.
-
$unbox
-
getMember
Exposes the wrapped Python value as a polyglot proxy member.Generated Python bridge classes implement
ProxyObjectthrough this interface so GraalPy can read members from the underlying Python object. Two Micronaut-specific members are handled before delegating to Python:HOST_OBJECT_MEMBERexposes a private host reference used to recover the generated Java wrapper, andAS_POLYGLOT_VALUE_MEMBERexposes a zero-argument callable that returns the wrappedValue. JavaBean-style generated accessor aliases are resolved after direct Python members.- Specified by:
getMemberin interfaceorg.graalvm.polyglot.proxy.ProxyObject- Parameters:
key- The requested member name.- Returns:
- The member value, a generated accessor callable, or
nullwhen the Python member isNoneor no member is available.
-
getMemberKeys
Returns member keys exposed by the wrapped Python object.Micronaut-specific synthetic members are intentionally omitted from the returned key set so Python-side enumeration reflects the user object's members.
- Specified by:
getMemberKeysin interfaceorg.graalvm.polyglot.proxy.ProxyObject- Returns:
- The wrapped Python member names as a
String[], or an empty array when the wrapped value has no members.
-
hasMember
Tests whether a member is available through this proxy.The check includes Micronaut's synthetic bridge members, direct members of the wrapped Python object, and generated JavaBean accessor aliases for bridge classes that implement
ValueCoercible.GeneratedPropertyMembers.- Specified by:
hasMemberin interfaceorg.graalvm.polyglot.proxy.ProxyObject- Parameters:
key- The member name to test.- Returns:
truewhen the member can be resolved.
-
putMember
Writes a member to the wrapped Python object.Python
Noneis converted to Javanull. Host objects that are themselvesValueCoercibleinstances are unwrapped to their Python value before assignment, andPooledValueCoercibleinstances are resolved in the target Python context so pooled event-loop objects are not mixed between contexts.- Specified by:
putMemberin interfaceorg.graalvm.polyglot.proxy.ProxyObject- Parameters:
key- The Python member name to write.value- The incoming polyglot value.
-
hostObject
Extracts a generated Java wrapper from a polyglot value when one is available.This method recognizes both direct host objects and Micronaut's synthetic
HOST_OBJECT_MEMBERback-reference.- Parameters:
value- The polyglot value to inspect.- Returns:
- The generated wrapper, or
nullwhen the value is not backed by aValueCoercible.
-
hostObject
Extracts a generated Java wrapper from a proxy object when one is available.This overload is used when code already has a
ProxyObjectview and needs to inspect Micronaut's syntheticHOST_OBJECT_MEMBERwithout first wrapping it as aValue.- Parameters:
value- The proxy object to inspect.- Returns:
- The generated wrapper, or
nullwhen the proxy does not expose one.
-
hostObject
Extracts a host object of the requested type from a polyglot value.The returned object may be a direct GraalPy host object or the generated Java wrapper recovered through
HOST_OBJECT_MEMBER.- Parameters:
value- The polyglot value to inspect.targetType- The required host object type.- Returns:
- The host object when it is assignable to
targetType; otherwisenull.
-
hostObject
static @Nullable Object hostObject(@Nullable org.graalvm.polyglot.proxy.ProxyObject value, Class<?> targetType) Extracts a host object of the requested type from a proxy object.This method checks Micronaut's synthetic
HOST_OBJECT_MEMBERand verifies the recovered host object before returning it.- Parameters:
value- The proxy object to inspect.targetType- The required host object type.- Returns:
- The host object when it is assignable to
targetType; otherwisenull.
-
matchesArgument
Match one Python argument against a Java parameter type without conversion.Runtime proxies expose all overloads for a Java method name through one Python callable. This quick check uses generated
ExecutableMethodmetadata and only boxes primitive types throughReflectionUtils; it deliberately avoids reflective probing of the generated proxy class while still letting Python-backed values expose their host wrapper viaHOST_OBJECT_MEMBER.- Parameters:
value- The Python argumenttargetType- The Java parameter type- Returns:
- Whether the argument can be passed to the generated method
-