Skip to content

JAX-RS: migrate DefaultValue annotation on request parameters #574

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
bottemav opened this issue Nov 27, 2022 · 4 comments · Fixed by #604
Closed

JAX-RS: migrate DefaultValue annotation on request parameters #574

bottemav opened this issue Nov 27, 2022 · 4 comments · Fixed by #604
Assignees
Labels
JEE/JAX-RS type: enhancement New feature or request

Comments

@bottemav
Copy link
Contributor

What needs to be done

Migrate javax.ws.rs.DefaultValue annotation on request parameters to the defaultValue attribute of org.springframework.web.bind.annotation.RequestParam

Why it needs to be done

javax.ws.rs.DefaultValue is one of the JAX-RS annotations that needs to be migrated to Spring Web. The annotation can be applied to a couple of request annotations like QueryParam, FormParam, PathParam, ... but let's start with QueryParam.

Acceptance Criteria

After applying the recipe, the RequestParam annotation has a defaultValue attribute with the same value as the javax.ws.rs.DefaultValue annotation and the javax.ws.rs.DefaultValue annotation is removed.

Given a method parameter annotated with both javax.ws.rs.DefaultValue and javax.ws.rs.QueryParam annotations
When the recipe MigrateJaxRsRecipe is applied
Then the method parameter is annotated with a org.springframework.web.bind.annotation.RequestParam having an defaultValue attribute with the same value as the javax.ws.rs.DefaultValue annotation

Additional Information

An example:
public String getAllPersons(@DefaultValue("0") @QueryParam("page") int page)
should be migrated to
public String getAllPersons(@RequestParam(required = false, value = "page", defaultValue="0") int page)

@fabapp2 fabapp2 added type: enhancement New feature or request JEE/JAX-RS labels Nov 30, 2022
@fabapp2
Copy link
Contributor

fabapp2 commented Nov 30, 2022

Thanks for adding this @bottemav
It's a long way to fully migrate JAX-RS to Boot...
would you like to look into it and contribute something as another step in this direction?

@bottemav
Copy link
Contributor Author

bottemav commented Dec 2, 2022

@fabapp2 Sure, I'd love to.

I think I will create a new Recipe for this

CopyAnnotationAttribute (
   String sourceAnnotation,
   String sourceAnnotationAttribute,
   String targetAnnotation,
   String targetAnnotationAttribute,
   boolean removeSourceAnnotation
)

For this ticket it will be used this way:

CopyAnnotationAttribute (
   "javax.ws.rs.DefaultValue", "value", "org.springframework.web.bind.annotation.RequestParam", "defaultValue", true
);

I'm still in doubt whether removing the source annotation is part of the recipe or not.

@fabapp2
Copy link
Contributor

fabapp2 commented Dec 7, 2022

HI @bottemav

I like the idea of implementing a generic recipe.
IMHO it should be an isolated step and not combined with deleting the recipe.
Mainly because I could imagine a composition of these recipes where multiple annotation attributes need to be moved and then you wouldn't want to delete the annotation straight away but do it in a separate step.
A quick check made me realize a DeleteAnnotaion does not exist.
I am more than open to discussing in case you have a different opinion.
I will assign this issue to you. Thanks for contributing 🚀

@fabapp2
Copy link
Contributor

fabapp2 commented Dec 7, 2022

@bottemav if you like you can join our Slack for faster/easier communication.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
JEE/JAX-RS type: enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants