Skip to content

jextract: support returning JavaKit wrapped Java objects (Resolves #841) - #851

Draft
amanmaurya92 wants to merge 1 commit into
swiftlang:mainfrom
amanmaurya92:fix/841-return-javakit-objects
Draft

jextract: support returning JavaKit wrapped Java objects (Resolves #841)#851
amanmaurya92 wants to merge 1 commit into
swiftlang:mainfrom
amanmaurya92:fix/841-return-javakit-objects

Conversation

@amanmaurya92

Copy link
Copy Markdown
Contributor

Description

Resolves #841. This PR adds support for returning JavaKit-wrapped Java objects (like JavaLong or JavaString) from Swift functions back to Java.

Approach

  • Type Detection: Updated translateResult, translateOptionalResult, and translateArrayResult in both NativeTranslation and JavaTranslation to recognize types passing the isSwiftJavaWrapper predicate.
  • Java Shim: Maps the return type to the corresponding underlying Java class (e.g., java.lang.Long) rather than throwing an unsupported type error.
  • Native Translation (C bindings): Returns the Swift value wrapped in an Optional, and calls .getJNIValue(in: environment) to safely extract and return the underlying JNI object reference (or NULL if missing).
  • Tests: Added tests to JNIJavaKitTests for functions returning standard wrappers, optional wrappers, and arrays of wrappers.

@amanmaurya92
amanmaurya92 requested a review from ktoso as a code owner July 27, 2026 02:33
@amanmaurya92
amanmaurya92 marked this pull request as draft July 27, 2026 03:10
@madsodgaard

Copy link
Copy Markdown
Contributor

I haven't read the code, but please also add some runtime tests to the JNI sample app

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

jextract: support returning JavaKit wrapped Java objects

2 participants