Skip to content

Declaring an argument with java.util.Optional results in input being double wrapped with Optional #156

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
janujc opened this issue Sep 29, 2021 · 1 comment
Assignees
Labels
status: duplicate A duplicate of another issue

Comments

@janujc
Copy link

janujc commented Sep 29, 2021

Hi, I'm on 1.0.0-M2 and trying to create a handler for a method with an optional field.

@QueryMapping
public Example example(@Argument Optional<String> relatedString) {
    return exampleService.getExample(relatedString);
}

However, I keep getting the following response:

{
    "errors": [
        {
            "message": "class java.util.Optional cannot be cast to class java.lang.String (java.util.Optional and java.lang.String are in module java.base of loader 'bootstrap')",
            "locations": [
                {
                    "line": 2,
                    "column": 5
                }
            ],
            "path": [
                "example"
            ],
            "extensions": {
                "classification": "INTERNAL_ERROR"
            }
        }
    ],
    "data": {
        "example": null
    }
}

When debugging, I found that relatedString was being double wrapped with Optional at runtime. In other words, the input to the method is actually Optional[Optional[stringThatMayBeHere]]. I assume that this is not intentional.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Sep 29, 2021
@bclozel bclozel self-assigned this Sep 30, 2021
@bclozel
Copy link
Member

bclozel commented Sep 30, 2021

This has been fixed in #122, and is available for testing in SNAPSHOTs.
Thanks!

@bclozel bclozel closed this as completed Sep 30, 2021
@bclozel bclozel added status: duplicate A duplicate of another issue and removed status: waiting-for-triage An issue we've not yet triaged labels Sep 30, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: duplicate A duplicate of another issue
Projects
None yet
Development

No branches or pull requests

3 participants