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.static interfaceThe Java base class members of a generated class that extends a Java class. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final Stringstatic final Stringstatic final StringThe member the Python view of a wrapper reads its Python object from, as opposed to the publicAS_POLYGLOT_VALUE_MEMBER, which always answers with the object of the wrapper itself.static final StringThe prefix of the attributes the runtime stores on a Python object, hidden from member enumeration.The accessors of the Java exception a generated exception wrapper exposes to Python. -
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.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:
-
PYTHON_OBJECT_MEMBER
The member the Python view of a wrapper reads its Python object from, as opposed to the publicAS_POLYGLOT_VALUE_MEMBER, which always answers with the object of the wrapper itself.The name is dunder-style so that Python does not mangle it inside the class body of the view, and carries the
RUNTIME_MEMBER_PREFIXso that it stays out of member enumeration.- See Also:
-
THROWABLE_MEMBERS
-
RUNTIME_MEMBER_PREFIX
The prefix of the attributes the runtime stores on a Python object, hidden from member enumeration.- 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.A generated wrapper that does not hold a Python object yet creates one on the first call, so the value is never
null: the default methods of this interface and the generated accessors read it without a null check.- 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. Three Micronaut-specific members are handled before delegating to Python:HOST_OBJECT_MEMBERexposes a private host reference used to recover the generated Java wrapper,AS_POLYGLOT_VALUE_MEMBERexposes a zero-argument callable that returns the wrappedValueof this wrapper, andPYTHON_OBJECT_MEMBERthe callable the Python view of the wrapper reads, which answers with the object of the context the caller runs in. JavaBean-style generated accessor aliases are resolved after direct Python members, and a wrapper that is aThrowableexposes the accessors of the Java exception (getMessage(),getCause(), ...), so a Python exception handler reads the Java view of a Python exception that crossed Java.- 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.
-