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

@ModelAttribute(binding=false) is not honored with WebFlux #26856

Closed
johnyannj opened this issue Apr 24, 2021 · 4 comments
Closed

@ModelAttribute(binding=false) is not honored with WebFlux #26856

johnyannj opened this issue Apr 24, 2021 · 4 comments
Assignees
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) status: backported An issue that has been backported to maintenance branches type: bug A general bug
Milestone

Comments

@johnyannj
Copy link

johnyannj commented Apr 24, 2021

Given...

public class User {
    private String name;

    public String getName() {
        return this.name;
    }

    public void setName(String name) {
        this.name = name;
    }
}

And...

@RestController
public class DemoController {

    @GetMapping("/hello")
    public Mono<String> hello(@ModelAttribute(binding = false) User user) {
        return Mono.just(user.getName());
    }
}

... when I call http://localhost:8080/hello?name=xxxx , I get "xxxx" for WebFlux but "" for Web MVC.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Apr 24, 2021
@sbrannen sbrannen changed the title ModelAttribute binding =flase does not work for weblux @ModelAttribute(binding=false) is not honored with WebFlux Apr 27, 2021
@sbrannen sbrannen added the in: web Issues in web modules (web, webmvc, webflux, websocket) label Apr 27, 2021
@sbrannen
Copy link
Member

Thanks for raising your first issue against the Spring Framework!

It appears that we may need to add a check to org.springframework.web.reactive.result.method.annotation.ModelAttributeMethodArgumentResolver.resolveArgument(MethodParameter, BindingContext, ServerWebExchange) to honor the binding attribute in @ModelAttribute.

We will investigate our options.

@sbrannen sbrannen self-assigned this Apr 27, 2021
@sbrannen sbrannen added type: bug A general bug and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Apr 27, 2021
@sbrannen sbrannen added this to the 5.3.7 milestone Apr 27, 2021
@sbrannen sbrannen changed the title @ModelAttribute(binding=false) is not honored with WebFlux @ModelAttribute(binding=false) is not honored with WebFlux Apr 29, 2021
sbrannen added a commit to sbrannen/spring-framework that referenced this issue Apr 30, 2021
@sbrannen
Copy link
Member

Current work on this can be viewed here: main...sbrannen:issues/gh-26856-ModelAttribute-binding-false-WebFlux

sbrannen added a commit to sbrannen/spring-framework that referenced this issue May 3, 2021
sbrannen added a commit to sbrannen/spring-framework that referenced this issue May 3, 2021
sbrannen added a commit to sbrannen/spring-framework that referenced this issue May 3, 2021
@sbrannen sbrannen added the for: backport-to-5.2.x Marks an issue as a candidate for backport to 5.2.x label May 3, 2021
@spring-projects-issues spring-projects-issues added status: backported An issue that has been backported to maintenance branches and removed for: backport-to-5.2.x Marks an issue as a candidate for backport to 5.2.x labels May 3, 2021
sbrannen added a commit that referenced this issue May 3, 2021
Prior to this commit, @ModelAttribute(binding=false) was honored with
Spring Web MVC but not with WebFlux.

This commit adds support for disabling binding via @ModelAttribute with
WebFlux by adding a check to resolveArgument(...) in
ModelAttributeMethodArgumentResolver.

Closes gh-26856
@sbrannen
Copy link
Member

sbrannen commented May 3, 2021

This has been addressed, and the fix will be available in Spring Framework 5.2.15 and 5.3.7 (and their upcoming snapshot builds).

sbrannen added a commit that referenced this issue May 4, 2021
Zoran0104 pushed a commit to Zoran0104/spring-framework that referenced this issue Aug 20, 2021
Prior to this commit, @ModelAttribute(binding=false) was honored with
Spring Web MVC but not with WebFlux.

This commit adds support for disabling binding via @ModelAttribute with
WebFlux by adding a check to resolveArgument(...) in
ModelAttributeMethodArgumentResolver.

Closes spring-projectsgh-26856
Zoran0104 pushed a commit to Zoran0104/spring-framework that referenced this issue Aug 20, 2021
lxbzmy pushed a commit to lxbzmy/spring-framework that referenced this issue Mar 26, 2022
Prior to this commit, @ModelAttribute(binding=false) was honored with
Spring Web MVC but not with WebFlux.

This commit adds support for disabling binding via @ModelAttribute with
WebFlux by adding a check to resolveArgument(...) in
ModelAttributeMethodArgumentResolver.

Closes spring-projectsgh-26856
lxbzmy pushed a commit to lxbzmy/spring-framework that referenced this issue Mar 26, 2022
@Wackerle
Copy link

I found a similar issue.

Given...

public class User {
    private String name = "";

    public String getName() {
        return this.name;
    }

    public void setName(String name) {
        this.name = name;
    }
}

And...

@RestController
public class DemoController {
    @ModelAttribute(binding = false)
    public User user() {
        return new User();
    }

    @GetMapping("/hello")
    public Mono<String> hello(@ModelAttribute User user) {
        return Mono.just(user.getName());
    }
}

when I call http://localhost:8080/hello?name=xxxx , I get "xxxx" .

The version I'm using: spring boot 2.6.6, spring framework 5.3.23.

But I know from here that the the description of the binding parameter is: 'Allows data binding to be disabled directly on an @ModelAttribute method parameter or on the attribute returned from an @ModelAttribute method, both of which would prevent data binding for that attribute. '

But it didn't actually take effect.

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) status: backported An issue that has been backported to maintenance branches type: bug A general bug
Projects
None yet
Development

No branches or pull requests

4 participants