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 records cannot be used for request beans with @PathVariable #8295

Closed
lbkulinski opened this issue Nov 6, 2022 · 6 comments
Closed

Java records cannot be used for request beans with @PathVariable #8295

lbkulinski opened this issue Nov 6, 2022 · 6 comments
Milestone

Comments

@lbkulinski
Copy link

Expected Behavior

I expect to be able to use Java records with @RequestBean and @PathVariable for API endpoints in the same way that I can declare a POJO.

Actual Behaviour

Instead, I get the following compilation error:

java: The route declares a uri variable named [id], but no corresponding method argument is present

Steps To Reproduce

  1. Clone the provided repository
  2. Run the Micronaut application
  3. See the following compilation error: java: The route declares a uri variable named [id], but no corresponding method argument is present

Environment Information

  • Operating System: macOS Ventura 13.0
  • JDK (I presume this would still occur on non-ea builds): openjdk 20-ea 2023-03-21
    OpenJDK Runtime Environment (build 20-ea+21-1545)
    OpenJDK 64-Bit Server VM (build 20-ea+21-1545, mixed mode, sharing)

Example Application

https://github.com/lbkulinski/record_bug_example

Version

3.7.3

@lbkulinski
Copy link
Author

@sdelamo @dstepanov Any help with this issue? Thanks!

yawkat added a commit that referenced this issue Nov 24, 2022
@dstepanov the MissingParameterRule patch is a bit weird, the properties returned by getBeanProperties don't include annotations. Should they?

Fixes #8295
@yawkat yawkat closed this as completed Dec 2, 2022
@yawkat
Copy link
Member

yawkat commented Dec 2, 2022

thanks for the report! will be fixed in 3.8

@graemerocher graemerocher added this to the 3.8.0 milestone Dec 2, 2022
@lbkulinski
Copy link
Author

@yawkat

thanks for the report! will be fixed in 3.8

Thanks for the quick turnaround! This will be super nice to use!

@lbkulinski
Copy link
Author

@yawkat Is this fix available in 3.8.0-SNAPSHOT? I recently picked a project back up that was trying to use it, and appear to be having issues with using @PathVariable and records still. The original example now compiles, but I am now getting the following when making a request:

{
    "message": "Bad Request",
    "_links": {
        "self": {
            "href": "/api/example/1",
            "templated": false
        }
    },
    "_embedded": {
        "errors": [
            {
                "message": "Required argument [Integer id] not specified",
                "path": "/id"
            }
        ]
    }
}

This occurs when I POST to /api/example/1, where 1 would be the value for the required id path variable. I have update the following repository, where you should be able to see the issue: https://github.com/lbkulinski/record_bug_example

Thanks!

@lbkulinski
Copy link
Author

@dstepanov @sdelamo Are you able to take a look at the comment above? Thanks and sorry for the trouble!

@lbkulinski
Copy link
Author

I opened #8551. Thanks!

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

No branches or pull requests

3 participants