Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Java - Self expansion of QueryParameters without reflection #3965

Closed
andreaTP opened this issue Jan 3, 2024 · 2 comments · Fixed by #3982
Closed

Java - Self expansion of QueryParameters without reflection #3965

andreaTP opened this issue Jan 3, 2024 · 2 comments · Fixed by #3982
Assignees
Labels
enhancement New feature or request help wanted Issue caused by core project dependency modules or library Java WIP
Milestone

Comments

@andreaTP
Copy link
Contributor

andreaTP commented Jan 3, 2024

I was reviewing this issue, and this proposal is aimed to fully remove all the usages of reflection in Java.

The QueryParameter type classes are currently using annotations, in combination with reflection up into abstractions (not easily swappable in user-land).
I do believe that a generated approach is preferable over the current implementation, it will also more closely resemble the design of the serialization/deserialization of the objects.

Code currently generated

class GetQueryParameters {
    /** Select properties to be returned */
    @QueryParameter(name = "%24select")
    @jakarta.annotation.Nullable public String[] select;

    /** Search items by search phrases */
    @QueryParameter(name = "%24search")
    @jakarta.annotation.Nullable public String search;
}

Proposal

class GetQueryParameters {
    /** Select properties to be returned */
    @jakarta.annotation.Nullable public String[] select;

    /** Search items by search phrases */
    @jakarta.annotation.Nullable public String search;

    public Map<String, Object> toQueryParameters() {
      return Map.of(
         "%24select", select,
         "%24search", search);
    }
}

the corresponding implementation of addQueryParameter simplifies to:

    public void addQueryParameters(@Nullable final Map<String, Object> parameters) {
        if (parameters == null) return;
        queryParameters.putAll(parameters);
    }

and the rest should be changed accordingly to make use of the new instance method.
After this change, we can safely delete the QueryParameter annotation, and the generated LOCs will be comparable with the current implementation.

I'm happy to hear feedback on this proposal and I can volunteer to implement it as I believe that removing reflection is one key aspect that will determine the success of Kiota in the Java ecosystem (e.g. being able to execute Kiota with zero configuration on native-image is the end goal).

@github-project-automation github-project-automation bot moved this to Todo in Kiota Jan 3, 2024
@baywet baywet added enhancement New feature or request help wanted Issue caused by core project dependency modules or library Java labels Jan 8, 2024
@baywet baywet added this to the Kiota v1.11 milestone Jan 8, 2024
@baywet
Copy link
Member

baywet commented Jan 8, 2024

Hi @andreaTP,
Thanks for the reminder on this.
I think this is promising, two things this proposal doesn't account for:

  • We need to check for null values before adding them in the addQueryParameters implementation.
  • The toQueryParameters method probably needs to have entries for query paramters where the URI Template parameter name matches the symbol name (I don't believe we emit annotations today when that's the case)

Other than that, if we don't anticipate a significant increase in size, we should proceed. And yes, please take it on if you can, this is time sensitive as this would be on the red-path for the Microsoft Graph Java SDK GA.

@andreaTP
Copy link
Contributor Author

andreaTP commented Jan 8, 2024

I don't think the increased size is going to be humongous, also, the advantage of completely removing reflection is really appealing!

I'll take it 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Issue caused by core project dependency modules or library Java WIP
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

2 participants