Skip to content

Add binding support to functional servlet and reactive stack #25943

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
mdeinum opened this issue Oct 21, 2020 · 4 comments
Closed

Add binding support to functional servlet and reactive stack #25943

mdeinum opened this issue Oct 21, 2020 · 4 comments
Assignees
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) type: enhancement A general enhancement
Milestone

Comments

@mdeinum
Copy link
Contributor

mdeinum commented Oct 21, 2020

When using regular @Controller for both the Servlet as well as the Reactive stack there is support for data binding using @ModelAttribute and there is support for deserializing a request body with @RequestBody.

When using the functional approach in either the Servlet or Reactive stack deserializing is supported through the body methods of the respective ServerRequest interface/implementation. There is no direct support for data-binding. It currently requires, some work, to do data-binding in a method.

public ServerResponse handle(ServerRequest request) {
  MyObject instance = new MyObject();
  ExtendedServletRequestDataBinder binder = new ExtendedServletRequestDataBinder(instance, "myObject");
  binder.bind(request.servletRequest());
  return ServerResponse.ok().render("view", instance).build();.
}

Although this will work it requires more knowledge of the internal of data binding then one should need.

It would be nice if there would be a supporting bind method(s) to support binding to a type like

<T> T bind(Class<?> bindType);
<T> T bind(Class<?> bindType, String objectName);

Which would reduce the code to something like this

public ServerResponse handle(ServerRequest request) {
  MyObject instance =request.bind(MyObject.class, "myObject");
  return ServerResponse.ok().render("view", instance).build();.
}

This could use the already available WebDataBinder implementations to do the binding (at least the reactive stack has a special DataBinder the functional servlet one needs to be created).

@mdeinum mdeinum changed the title Add binding support to Add binding support to functional servlet and reactive stack Oct 21, 2020
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Oct 21, 2020
@rstoyanchev rstoyanchev added in: web Issues in web modules (web, webmvc, webflux, websocket) type: enhancement A general enhancement and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Oct 21, 2020
@rstoyanchev rstoyanchev added this to the 5.x Backlog milestone Oct 21, 2020
@rstoyanchev
Copy link
Contributor

Indeed, there is no binding in neither WebFlux.fn nor WebMvc.fn currently.

@poutsma poutsma self-assigned this Oct 23, 2020
@poutsma poutsma modified the milestones: 5.x Backlog, 5.3.2 Dec 2, 2020
@poutsma
Copy link
Contributor

poutsma commented Dec 3, 2020

This turned out to be more complicated than I initially considered, but it will make it into 5.3.3 I hope.

@poutsma
Copy link
Contributor

poutsma commented Mar 24, 2021

In order for the functional endpoints to support constructor binding, we will need to refactor some code out of the model attribute argument resolvers. See #26721.

@poutsma
Copy link
Contributor

poutsma commented Jun 28, 2023

With #26721 resolved, we should be able to get this enhancement in 6.1.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

5 participants