@JsonView is not consistent with SpringWeb MVC
Is your feature request related to a problem? Please describe.
- I want to apply
@JsonViewto only ResponseBody and not to RequestBody to achieve this I am annotating@JsonViewat the method level inRestControlleras follows
@PostMapping
@JsonView(UserViews.Internal.class)
public User createUser(@RequestBody CreateUserRequest createUserRequest) {
return new User("name", "lastName", 10);
}
With this configuration the API is working fine and returning the correct field in response as mentioned in JsonView, but Swagger doc is applying this JsonView to both request and response objects i.e CreateUserRequest as well as User.
Is this a bug ? or is there any way to achieve this?
Check the attached screenshot for reference where the internal schema for both request and response objects was created.
I've the same problem
@beatfreaker,
You should apply different @JsonView in your RequestBody.
This is an example how to achieve it:
https://github.com/springdoc/springdoc-openapi/blob/bfc57abd40178e91e24121e5266aee025026788d/springdoc-openapi-starter-webmvc-api/src/test/java/test/org/springdoc/api/v30/app54/HelloController.java#L56-L61