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

Allow org.springframework.web.bind.annotation.RequestBody on fields (and setters) [SPR-17515] #22047

Open
spring-projects-issues opened this issue Nov 18, 2018 · 0 comments
Labels
in: web type: enhancement
Milestone

Comments

@spring-projects-issues
Copy link
Collaborator

@spring-projects-issues spring-projects-issues commented Nov 18, 2018

Behrang Saeedzadeh opened SPR-17515 and commented

Currently, the correct handler signature to handle a request such as

POST http://localhost:8080/points?x=640&y=480
Content-Type: application/json

{ "circle": { "radius": "3.14" } } 

is something like:

@PostMapping
public 
CreateShapResponse
createShape(CreateShapeParams params, @RequestBody CreateShapeBody body) {

}

@Data
public class CreateShapeParams {

    private Double x;

    private Double y;

}

@Data
public class CreateShapeBody {

    private Circle;

    @Data
    public static class Circle {
        private Double radius;
    }
}

It would be nice if it was possible to merge the CreateShapeParams and CreateShapeBody POJOs into one CreateShapeRequest and have a single argument handler method. Then we could rewrite the controller as:

@PostMapping 
public 
CreateShapResponse
createShape(CreateShapeRequest request) {

} 

@Data
public class CreateShapeRequest {

    private Double x;

    private Double y;

    @RequestBody
    private Body body;

    @Data 
    public static class Body { 

        private Circle; 

        @Data
        public static class Circle {
            private Double radius;
        } 
    }
}

This would enable an API structure that is becoming more and more common.

For example, AWS SDKs have XyzRequest classes that encapsulate all the request details, from parameters to body and, IIRC, headers too (which means org.springframework.web.bind.annotation.RequestHeader should be allowed on POJO fields and setters too).

Response-side annotations (e.g. ResponseBody, ResponseStatus, etc.) should be allowed on fields (and setters) as well.


No further details from SPR-17515

@spring-projects-issues spring-projects-issues added type: enhancement in: web labels Jan 11, 2019
@spring-projects-issues spring-projects-issues added this to the 5.x Backlog milestone Jan 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: web type: enhancement
Projects
None yet
Development

No branches or pull requests

1 participant