Skip to content

Allow custom HandlerMethodArgumentResolvers to override built-ins #634

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

Closed
trehak1 opened this issue Mar 14, 2023 · 2 comments
Closed

Allow custom HandlerMethodArgumentResolvers to override built-ins #634

trehak1 opened this issue Mar 14, 2023 · 2 comments
Labels
status: declined A suggestion or change that we don't feel we should currently apply

Comments

@trehak1
Copy link

trehak1 commented Mar 14, 2023

We have DTOs shared across Graphql and REST, using JSON, with constructors like this:

    @JsonCreator
    public Extension(@Nonnull @JsonProperty("userId") UUID userId,
                     @Nonnull @JsonProperty("extensionName") String extensionName,
                     @Nonnull @JsonProperty("isBase64Encoded") Boolean base64,
                     @Nonnull @JsonProperty("extension") String extension) {
        this.userId = userId;
        this.extensionName = extensionName;
        this.base64 = base64;
        this.extension = extension;
    }

I'd love to use my custom HandlerMethodArgumentResolver as now supported in main.
However, custom argument resolvers comes LAST, therefore code using the input object described above fails on exception while default binder is trying to deserialize it using constructor deserializer.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Mar 14, 2023
@rstoyanchev
Copy link
Contributor

rstoyanchev commented Mar 22, 2023

This is for an @Argument method parameter? Currently GraphQlArgumentBinder does not expose object creation. That's what #521 aims to do. So will your custom argument resolver replace the one for @Argument completely? In which case, a custom annotation, e.g. @JsonArgument makes sense, and built-in resolvers will not interfere.

Generally in Spring MVC and elsewhere we order custom resolvers after the built-in ones, and instead of replacing them completely, we try to provide the necessary control over their behavior. That way the built-in method parameters have a predictable, well-known behavior, and if that doesn't work for you, then you can create your own, but keeping that separate in the programming model.

@rstoyanchev rstoyanchev added the status: waiting-for-feedback We need additional information before we can continue label Mar 22, 2023
@trehak1
Copy link
Author

trehak1 commented Mar 23, 2023

Sure, #521 is a way to go.

@trehak1 trehak1 closed this as completed Mar 23, 2023
@bclozel bclozel added status: declined A suggestion or change that we don't feel we should currently apply and removed status: waiting-for-feedback We need additional information before we can continue status: waiting-for-triage An issue we've not yet triaged labels Mar 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: declined A suggestion or change that we don't feel we should currently apply
Projects
None yet
Development

No branches or pull requests

4 participants